diff options
Diffstat (limited to 'src/runtime/debug')
| -rw-r--r-- | src/runtime/debug/garbage.go | 6 | ||||
| -rw-r--r-- | src/runtime/debug/garbage_test.go | 2 |
2 files changed, 3 insertions, 5 deletions
diff --git a/src/runtime/debug/garbage.go b/src/runtime/debug/garbage.go index 27adc70fd3..785e9d4598 100644 --- a/src/runtime/debug/garbage.go +++ b/src/runtime/debug/garbage.go @@ -89,11 +89,7 @@ func ReadGCStats(stats *GCStats) { // at startup, or 100 if the variable is not set. // A negative percentage disables garbage collection. func SetGCPercent(percent int) int { - old := setGCPercent(int32(percent)) - if percent >= 0 { - runtime.GC() - } - return int(old) + return int(setGCPercent(int32(percent))) } // FreeOSMemory forces a garbage collection followed by an diff --git a/src/runtime/debug/garbage_test.go b/src/runtime/debug/garbage_test.go index 37417aca2c..acc781ebdc 100644 --- a/src/runtime/debug/garbage_test.go +++ b/src/runtime/debug/garbage_test.go @@ -160,6 +160,8 @@ func TestSetGCPercent(t *testing.T) { runtime.ReadMemStats(&ms) ngc1 := ms.NumGC SetGCPercent(10) + // It may require an allocation to actually force the GC. + setGCPercentSink = make([]byte, 1<<20) runtime.ReadMemStats(&ms) ngc2 := ms.NumGC if ngc1 == ngc2 { |
