gc.go 344 B

12345678910111213141516171819202122232425262728293031
  1. package utils
  2. import (
  3. "runtime"
  4. "runtime/debug"
  5. "sync"
  6. "time"
  7. )
  8. var Gmutex sync.Mutex
  9. var ReqCount int
  10. func GC() {
  11. Gmutex.Lock()
  12. defer Gmutex.Unlock()
  13. ReqCount++
  14. if ReqCount >= 100 {
  15. runtime.GC()
  16. ReqCount = 0
  17. }
  18. }
  19. func Free() {
  20. for {
  21. if time.Now().Hour() == 1 {
  22. debug.FreeOSMemory()
  23. }
  24. time.Sleep(1 * time.Hour)
  25. }
  26. }