aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Amedee <carlos@golang.org>2024-12-11 11:16:57 -0500
committerGopher Robot <gobot@golang.org>2024-12-11 12:51:11 -0800
commit41b60aeefbe4ffd7e1aa3cadb5b005486c7b2914 (patch)
tree5cfa1e19f26bc4835d0d86df9b735ae49fabf9b5
parent6ec293f546298268b36c8240e3f75f5f1a2b0356 (diff)
downloadgo-x-website-41b60aeefbe4ffd7e1aa3cadb5b005486c7b2914.tar.xz
_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 <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Carlos Amedee <carlos@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
-rw-r--r--_content/doc/go1.24.md17
1 files changed, 10 insertions, 7 deletions
diff --git a/_content/doc/go1.24.md b/_content/doc/go1.24.md
index d3ef2b22..9b63d545 100644
--- a/_content/doc/go1.24.md
+++ b/_content/doc/go1.24.md
@@ -161,6 +161,16 @@ The new builtin `map` implementation and new runtime-internal mutex may be
disabled by setting `GOEXPERIMENT=noswissmap` and `GOEXPERIMENT=nospinbitmutex`
at build time respectively.
+The new [`AddCleanup`](/pkg/runtime#AddCleanup) function attaches a cleanup
+function to a pointer. Once the object that the pointer points to is no longer
+reachable, the runtime will call the function.
+[`AddCleanup`](/pkg/runtime#AddCleanup) is a finalization mechanism that is
+more flexible and less error-prone than [`SetFinalizer`](/pkg/runtime#SetFinalizer).
+Unlike [`SetFinalizer`](/pkg/runtime#SetFinalizer), it does not resurrect the
+object it is attached to for finalization and multiple cleanups may be attached
+to a single object. New code should prefer [`AddCleanup`](/pkg/runtime#AddCleanup)
+over [`SetFinalizer`](/pkg/runtime#SetFinalizer).
+
## Compiler {#compiler}
<!-- go.dev/issue/60725, go.dev/issue/57926 -->
@@ -604,13 +614,6 @@ The [`GOROOT`](/pkg/runtime#GOROOT) function is now deprecated.
In new code prefer to use the system path to locate the “go” binary,
and use `go env GOROOT` to find its GOROOT.
-The [`AddCleanup`](/pkg/runtime#AddCleanup) function attaches a function to a pointer. Once the object that
-the pointer points to is no longer reachable, the runtime will call the function.
-[`AddCleanup`](/pkg/runtime#AddCleanup) is a finalization mechanism similar to [`SetFinalizer`](/pkg/runtime#SetFinalizer). Unlike
-[`SetFinalizer`](/pkg/runtime#SetFinalizer), it does not resurrect objects while running the cleanup. Multiple
-cleanups can be attached to a single object. [`AddCleanup`](/pkg/runtime#AddCleanup) is an improvement over
-[`SetFinalizer`](/pkg/runtime#SetFinalizer).
-
#### [`strings`](/pkg/strings/)
The [`strings`](/pkg/strings) package adds several functions that work with iterators: