Radar · Go · Archive · Week 10 · Mar 3 – 9, 2025
From unique to cleanups and weak: new low‑level tools for efficiency
Nice to knowruntime
- What changed
- The blog announces the introduction of weak pointers and improved finalization in Go 1.24.
- Production impact
- The source does not say.
- Try it
- Read the blog to understand how weak pointers can reduce memory pressure in long‑running services.
- Source
- go.dev/blog/cleanups-and-weak
Understand it, then run it
Go 1.24 adds two new low‑level tools that let you clean up resources more reliably and keep references to objects without stopping them from being garbage‑collected. The first is runtime.AddCleanup, which lets you attach a function to an object that runs when that object is no longer reachable. The second is weak.Pointer, a pointer type that the garbage collector ignores when deciding reachability. Together, they let you build caches that automatically drop entries when nothing else refers to them, and they avoid the pitfalls of the older runtime.SetFinalizer approach.
Written by gpt-oss-20b from the linked source · claims checked against the sources · archive, not individually reviewed