| // 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. |
| const filler int64 = 0x123456789abcdef0 |
| func (h *HeapObj) init() { |
| for i := 0; i < len(*h); i++ { |
| func (h *HeapObj) check() { |
| for i := 0; i < len(*h); i++ { |
| err = "filler overwritten" |
| func gc(shouldFinalize bool) { |
| if shouldFinalize != finalized { |
| err = "heap object finalized at the wrong time" |
| runtime.SetFinalizer(s.h, func(h *HeapObj) { |
| gc(true) // finalize here, after return value's last use. (Go1.11 never runs the finalizer.) |
| func g(p *StackObj) (v *HeapObj) { |
| v = p.h // last use of the stack object. the only reference to the heap object is in the return slot. |