| // Copyright 2018 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| // encourage heap object to be collected, and have its finalizer run. |
| gc() // prior to stack objects, heap object is not collected until here |
| panic("heap object never collected") |
| panic(fmt.Sprintf("expected collection at phase 1, got phase %d", c)) |
| runtime.SetFinalizer(s.h, func(h *HeapObj) { |
| // Remember at what phase the heap object was collected. |
| gc() // heap object is still live here |
| gc() // heap object should be collected here |