From: Brad Fitzpatrick Date: Tue, 6 Dec 2016 19:55:10 +0000 (+0000) Subject: runtime/debug: don't run a GC when setting SetGCPercent negative X-Git-Tag: go1.9beta1~1621 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=9f75ecd5e12f2b9988086954933d610cd5647918;p=gostls13.git runtime/debug: don't run a GC when setting SetGCPercent negative If the user is calling SetGCPercent(-1), they intend to disable GC. They probably don't intend to run one. If they do, they can call runtime.GC themselves. Change-Id: I40ef40dfc7e15193df9ff26159cd30e56b666f73 Reviewed-on: https://go-review.googlesource.com/34013 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Austin Clements --- diff --git a/src/runtime/debug/garbage.go b/src/runtime/debug/garbage.go index c82c024235..27adc70fd3 100644 --- a/src/runtime/debug/garbage.go +++ b/src/runtime/debug/garbage.go @@ -90,7 +90,9 @@ func ReadGCStats(stats *GCStats) { // A negative percentage disables garbage collection. func SetGCPercent(percent int) int { old := setGCPercent(int32(percent)) - runtime.GC() + if percent >= 0 { + runtime.GC() + } return int(old) }