The Strengths of the `weak` Package: Weak Pointers Arrive in Go
summary
Go adds a small generics-based weak package that exposes weak.make and weak.Value to create non-owning pointers that return nil after GC, so you must nil-check every resolve; examples implement an in-memory cache that lets the collector reclaim entries and an observer pattern where subscribers don’t prolong subjects. The runtime tool used in demos is runtime.GC to force collection. Weak pointers are thread-safe, interact with escape analysis and heap allocation, and the new experimental GreenTea GC reports 10–40% marking CPU reduction on Intel workloads.
AI-written summary · about
chapters (10)
- 0:00Introduction
- 2:11Overview of weak pointers
- 7:35Working with weak pointers
- 13:43Garbage collection in Go
- 23:45GC characteristics and tuning
- 28:49Experimental GC and features
- 36:54Language comparison
- 38:08Caching use case
- 43:07Observer pattern use case
- 49:29Best practices and conclusion








