12345678910111213141516171819202122232425262728293031 |
- package utils
- import (
- "runtime"
- "runtime/debug"
- "sync"
- "time"
- )
- var Gmutex sync.Mutex
- var ReqCount int
- func GC() {
- Gmutex.Lock()
- defer Gmutex.Unlock()
- ReqCount++
- if ReqCount >= 100 {
- runtime.GC()
- ReqCount = 0
- }
- }
- func Free() {
- for {
- if time.Now().Hour() == 1 {
- debug.FreeOSMemory()
- }
- time.Sleep(1 * time.Hour)
- }
- }
|