@@ -161,6 +161,16 @@ The new builtin `map` implementation and new runtime-internal mutex may be
161
161
disabled by setting ` GOEXPERIMENT=noswissmap ` and ` GOEXPERIMENT=nospinbitmutex `
162
162
at build time respectively.
163
163
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
+
164
174
## Compiler {#compiler}
165
175
166
176
<!-- go.dev/issue/60725, go.dev/issue/57926 -->
@@ -604,13 +614,6 @@ The [`GOROOT`](/pkg/runtime#GOROOT) function is now deprecated.
604
614
In new code prefer to use the system path to locate the “go” binary,
605
615
and use ` go env GOROOT ` to find its GOROOT.
606
616
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
-
614
617
#### [ ` strings ` ] ( /pkg/strings/ )
615
618
616
619
The [ ` strings ` ] ( /pkg/strings ) package adds several functions that work with iterators:
0 commit comments