Source file
test/gc2.go
1
2
3
4
5
6
7
8
9
10
11
12
13 package main
14
15 import (
16 "fmt"
17 "os"
18 "runtime"
19 )
20
21 func main() {
22 const N = 10000
23 st := new(runtime.MemStats)
24 memstats := new(runtime.MemStats)
25 runtime.ReadMemStats(st)
26 for i := 0; i < N; i++ {
27 c := make(chan int, 10)
28 _ = c
29 if i%100 == 0 {
30 for j := 0; j < 4; j++ {
31 runtime.GC()
32 runtime.Gosched()
33 runtime.GC()
34 runtime.Gosched()
35 }
36 }
37 }
38
39 runtime.ReadMemStats(memstats)
40 obj := int64(memstats.HeapObjects - st.HeapObjects)
41 if obj > N/5 {
42 fmt.Println("too many objects left:", obj)
43 os.Exit(1)
44 }
45 }
46
View as plain text