free_os_memory.go 659 B

12345678910111213141516171819
  1. package job
  2. import "runtime/debug"
  3. // MemoryReleaseJob returns freed heap spans to the OS so steady-state RSS tracks
  4. // the live heap between the bursty traffic-collection jobs, instead of lingering
  5. // at the high-water mark until the scavenger lazily reclaims it.
  6. type MemoryReleaseJob struct{}
  7. // NewMemoryReleaseJob creates a new memory-release job instance.
  8. func NewMemoryReleaseJob() *MemoryReleaseJob {
  9. return new(MemoryReleaseJob)
  10. }
  11. // Run forces a GC and returns as much free memory to the OS as possible. It is
  12. // scheduled on a minutes cadence because FreeOSMemory triggers a full GC.
  13. func (j *MemoryReleaseJob) Run() {
  14. debug.FreeOSMemory()
  15. }