1 // $G $D/$F.go && $L $F.$A && ./$A.out
3 // Copyright 2011 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 // Check that buffered channels are garbage collected properly.
8 // An interesting case because they have finalizers and used to
9 // have self loops that kept them from being collected.
10 // (Cyclic data with finalizers is never finalized, nor collected.)
22 st := new(runtime.MemStats)
23 memstats := new(runtime.MemStats)
24 runtime.ReadMemStats(st)
25 for i := 0; i < N; i++ {
26 c := make(chan int, 10)
29 for j := 0; j < 4; j++ {
38 runtime.ReadMemStats(memstats)
39 obj := memstats.HeapObjects - st.HeapObjects
41 fmt.Println("too many objects left:", obj)