aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2024-12-26 17:24:09 -0500
committerAustin Clements <austin@google.com>2025-01-02 08:05:04 -0800
commit6d1521c58f8fcf1b27d2e1b25cca29987b557dee (patch)
treeaab3493cca8481bfe4af946f07132ee43416acc8
parent686c830bcb6dbc45421dce08a724e74b8f71769d (diff)
downloadgo-x-website-6d1521c58f8fcf1b27d2e1b25cca29987b557dee.tar.xz
_content/doc/go1.24: dedicated subsection for AddCleanup
AddCleanup is a new library routine. I think the fact that it's in the runtime package is largely irrelevant to the user, so this CL moves the documentation on AddCleanup out of the runtime section and into a new subsection of "Standard library". It also tidies up the text. Change-Id: I0609f48d3043bbd84bb0ef1e8c21f44baf8f1764 Reviewed-on: https://go-review.googlesource.com/c/website/+/638560 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
-rw-r--r--_content/doc/go1.24.md25
1 files changed, 15 insertions, 10 deletions
diff --git a/_content/doc/go1.24.md b/_content/doc/go1.24.md
index 9df35e5e..824c5d10 100644
--- a/_content/doc/go1.24.md
+++ b/_content/doc/go1.24.md
@@ -167,16 +167,6 @@ 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 -->
@@ -225,6 +215,21 @@ Benchmarks may now use the faster and less error-prone [`testing.B.Loop`](/pkg/t
- The benchmark function will execute exactly once per -count, so expensive setup and cleanup steps execute only once.
- Function call parameters and results are kept alive, preventing the compiler from fully optimizing away the loop body.
+### Improved finalizers
+
+<!-- go.dev/issue/67535 -->
+The new [`runtime.AddCleanup`](/pkg/runtime#AddCleanup) function is a
+finalization mechanism that is more flexible, more efficient, and less
+error-prone than [`runtime.SetFinalizer`](/pkg/runtime#SetFinalizer).
+`AddCleanup` attaches a cleanup function to an object that will run once
+the object is no longer reachable.
+However, unlike `SetFinalizer`,
+multiple cleanups may be attached to a single object,
+cleanups may be attached to interior pointers,
+cleanups do not generally cause leaks when objects form a cycle, and
+cleanups do not delay the freeing of an object or objects it points to.
+New code should prefer `AddCleanup` over `SetFinalizer`.
+
### New crypto/mlkem package {#crypto-mlkem}
<!-- go.dev/issue/70122 -->