3 //go:build !nacl && !js
5 // Copyright 2011 The Go Authors. All rights reserved.
6 // Use of this source code is governed by a BSD-style
7 // license that can be found in the LICENSE file.
9 // Test that buffered channels are garbage collected properly.
10 // An interesting case because they have finalizers and used to
11 // have self loops that kept them from being collected.
12 // (Cyclic data with finalizers is never finalized, nor collected.)
24 st := new(runtime.MemStats)
25 memstats := new(runtime.MemStats)
26 runtime.ReadMemStats(st)
27 for i := 0; i < N; i++ {
28 c := make(chan int, 10)
31 for j := 0; j < 4; j++ {
40 runtime.ReadMemStats(memstats)
41 obj := int64(memstats.HeapObjects - st.HeapObjects)
43 fmt.Println("too many objects left:", obj)