mirror of
https://github.com/jlelse/GoBlog
synced 2024-06-29 11:27:34 +00:00
25 lines
373 B
Go
25 lines
373 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"log"
|
||
|
"runtime"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
func initGC() {
|
||
|
go func() {
|
||
|
ticker := time.NewTicker(10 * time.Minute)
|
||
|
for range ticker.C {
|
||
|
go doGC()
|
||
|
}
|
||
|
}()
|
||
|
}
|
||
|
|
||
|
func doGC() {
|
||
|
var old, new runtime.MemStats
|
||
|
runtime.ReadMemStats(&old)
|
||
|
runtime.GC()
|
||
|
runtime.ReadMemStats(&new)
|
||
|
log.Printf("Alloc: %v MiB → %v MiB", old.Alloc/1024/1024, new.Alloc/1024/1024)
|
||
|
}
|