diff options
| author | Anuraag Agrawal <anuraaga@gmail.com> | 2024-06-06 04:24:26 +0000 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2024-06-07 01:56:56 +0000 |
| commit | f7c330eac7777612574d8a1652fd415391f6095e (patch) | |
| tree | 71043151503ee94eb2730889d8da5a809cb6d539 /src | |
| parent | cf501e05e138e6911f759a5db786e90b295499b9 (diff) | |
| download | go-f7c330eac7777612574d8a1652fd415391f6095e.tar.xz | |
runtime: add a note on SetFinalizer doc about method receiver
A method receiver can be collected during the execution of that method.
This does make sense when thinking about how the GC would work, but
also seems not very obvious, so a point in the docs can increase the
chance of avoiding issues caused by missing KeepAlive of method
receivers.
Change-Id: I6817237dd022b5729dbdcda1b9f70c7059605575
GitHub-Last-Rev: 878bf3fde7b4ed66be0302ffdd5e704b4cd70a6c
GitHub-Pull-Request: golang/go#67777
Reviewed-on: https://go-review.googlesource.com/c/go/+/589735
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/runtime/mfinal.go | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/runtime/mfinal.go b/src/runtime/mfinal.go index 9dcafb427f..78313fb74c 100644 --- a/src/runtime/mfinal.go +++ b/src/runtime/mfinal.go @@ -377,9 +377,11 @@ func blockUntilEmptyFinalizerQueue(timeout int64) bool { // In order to use finalizers correctly, the program must ensure that // the object is reachable until it is no longer required. // Objects stored in global variables, or that can be found by tracing -// pointers from a global variable, are reachable. For other objects, -// pass the object to a call of the [KeepAlive] function to mark the -// last point in the function where the object must be reachable. +// pointers from a global variable, are reachable. A function argument or +// receiver may become unreachable at the last point where the function +// mentions it. To make an unreachable object reachable, pass the object +// to a call of the [KeepAlive] function to mark the last point in the +// function where the object must be reachable. // // For example, if p points to a struct, such as os.File, that contains // a file descriptor d, and p has a finalizer that closes that file |
