From 60d0a5375552edb308029c0e74fbe49d95e3e5e9 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Mon, 13 Dec 2021 16:19:07 +0400 Subject: [PATCH] run debug.FreeOSMemory when forcing GC (#16) --- watchdog.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/watchdog.go b/watchdog.go index a78ea1f..eeeb7d9 100644 --- a/watchdog.go +++ b/watchdog.go @@ -36,6 +36,11 @@ var ( // Clock can be used to inject a mock clock for testing. Clock = clock.New() + // ForcedGCFunc specifies the function to call when forced GC is necessary. + // Its default value is runtime.GC, but it can be set to debug.FreeOSMemory + // to force the release of memory to the OS. + ForcedGCFunc = runtime.GC + // NotifyGC, if non-nil, will be called when a GC has happened. // Deprecated: use RegisterPostGCNotifee instead. NotifyGC func() = func() {} @@ -370,7 +375,7 @@ func forceGC(memstats *runtime.MemStats) { // finalizers are run in the sweep phase. start := time.Now() notificationsTook := start.Sub(startNotify) - runtime.GC() + ForcedGCFunc() took := time.Since(start) memstatsFn(memstats)