123456789101112131415161718192021222324252627282930313233 |
- 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() == 0 {
- Gmutex.Lock()
- debug.FreeOSMemory()
- Gmutex.Unlock()
- }
- time.Sleep(1 * time.Hour)
- }
- }
|