3 // Copyright 2014 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 // Scenario that used to leak arbitrarily many SudoG structs.
8 // See golang.org/issue/9110.
21 debug.SetGCPercent(1000000) // only GC when we ask for GC
23 var stats, stats1, stats2 runtime.MemStats
26 for i := 0; i < 20; i++ {
28 // Should be warmed up by now.
29 runtime.ReadMemStats(&stats1)
33 for i := 0; i < 10; i++ {
42 time.Sleep(1 * time.Millisecond)
45 close(c) // let select put its sudog's into the cache
46 time.Sleep(1 * time.Millisecond)
57 time.Sleep(1 * time.Millisecond)
68 time.Sleep(1 * time.Millisecond)
72 time.Sleep(1 * time.Millisecond)
74 // drop cache on floor
77 // release cond2 after select has gotten to run
80 time.Sleep(1 * time.Millisecond)
86 runtime.ReadMemStats(&stats2)
88 if int(stats2.HeapObjects)-int(stats1.HeapObjects) > 20 { // normally at most 1 or 2; was 300 with leak
89 print("BUG: object leak: ", stats.HeapObjects, " -> ", stats1.HeapObjects, " -> ", stats2.HeapObjects, "\n")