os.go 362 B

12345678910111213141516171819202122
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package util
  4. import (
  5. "runtime/debug"
  6. "time"
  7. )
  8. // FreeOSMemory 强制回放内存资源
  9. func FreeOSMemory() {
  10. // 每一小时触发一次
  11. t := time.NewTicker(time.Hour)
  12. defer t.Stop()
  13. go func() {
  14. for {
  15. <-t.C
  16. debug.FreeOSMemory()
  17. }
  18. }()
  19. }