From 41b60aeefbe4ffd7e1aa3cadb5b005486c7b2914 Mon Sep 17 00:00:00 2001 From: Carlos Amedee Date: Wed, 11 Dec 2024 11:16:57 -0500 Subject: _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 Auto-Submit: Carlos Amedee Reviewed-by: Cherry Mui --- _content/doc/go1.24.md | 17 ++++++++++------- 1 file 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} @@ -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: -- cgit v1.3