Skip to content

Commit 41b60ae

Browse files
cagedmantisgopherbot
authored andcommitted
_content/doc: update runtime.AddCleanup note
For golang/go#68545 For golang/go#67535 Change-Id: I8d15c5645a50a50a035b3c531a6ceb4324e26364 Reviewed-on: https://go-review.googlesource.com/c/website/+/635275 LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Carlos Amedee <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent 6ec293f commit 41b60ae

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

_content/doc/go1.24.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,16 @@ The new builtin `map` implementation and new runtime-internal mutex may be
161161
disabled by setting `GOEXPERIMENT=noswissmap` and `GOEXPERIMENT=nospinbitmutex`
162162
at build time respectively.
163163

164+
The new [`AddCleanup`](/pkg/runtime#AddCleanup) function attaches a cleanup
165+
function to a pointer. Once the object that the pointer points to is no longer
166+
reachable, the runtime will call the function.
167+
[`AddCleanup`](/pkg/runtime#AddCleanup) is a finalization mechanism that is
168+
more flexible and less error-prone than [`SetFinalizer`](/pkg/runtime#SetFinalizer).
169+
Unlike [`SetFinalizer`](/pkg/runtime#SetFinalizer), it does not resurrect the
170+
object it is attached to for finalization and multiple cleanups may be attached
171+
to a single object. New code should prefer [`AddCleanup`](/pkg/runtime#AddCleanup)
172+
over [`SetFinalizer`](/pkg/runtime#SetFinalizer).
173+
164174
## Compiler {#compiler}
165175

166176
<!-- go.dev/issue/60725, go.dev/issue/57926 -->
@@ -604,13 +614,6 @@ The [`GOROOT`](/pkg/runtime#GOROOT) function is now deprecated.
604614
In new code prefer to use the system path to locate the “go” binary,
605615
and use `go env GOROOT` to find its GOROOT.
606616

607-
The [`AddCleanup`](/pkg/runtime#AddCleanup) function attaches a function to a pointer. Once the object that
608-
the pointer points to is no longer reachable, the runtime will call the function.
609-
[`AddCleanup`](/pkg/runtime#AddCleanup) is a finalization mechanism similar to [`SetFinalizer`](/pkg/runtime#SetFinalizer). Unlike
610-
[`SetFinalizer`](/pkg/runtime#SetFinalizer), it does not resurrect objects while running the cleanup. Multiple
611-
cleanups can be attached to a single object. [`AddCleanup`](/pkg/runtime#AddCleanup) is an improvement over
612-
[`SetFinalizer`](/pkg/runtime#SetFinalizer).
613-
614617
#### [`strings`](/pkg/strings/)
615618

616619
The [`strings`](/pkg/strings) package adds several functions that work with iterators:

0 commit comments

Comments
 (0)