Source file
test/fixedbugs/issue54343.go
1
2
3
4
5
6
7 package main
8
9 import "runtime"
10
11 func main() {
12 if wait() {
13 panic("GC'd early")
14 }
15 m = nil
16 if !wait() {
17 panic("never GC'd")
18 }
19 }
20
21 var m = New[int]().M
22
23 func New[X any]() *T[X] {
24 p := new(T[X])
25 runtime.SetFinalizer(p, func(*T[X]) { close(done) })
26 return p
27 }
28
29 type T[X any] [4]int
30
31 func (*T[X]) M() {}
32
33 var done = make(chan int)
34
35 func wait() bool {
36 for i := 0; i < 10; i++ {
37 runtime.GC()
38 select {
39 case <-done:
40 return true
41 default:
42 }
43 }
44 return false
45 }
46
View as plain text