What Is a Weak Reference?
A weak reference refers to an object without contributing to its reference count or otherwise preventing it from being collected. When the last strong reference goes away, the object can be freed even if weak references remain, and those references then report that the target is gone. It lets code observe an object without owning it.
Why it matters
Weak references break the reference cycles that would otherwise leak memory under reference counting, such as parent-child back-pointers. They also power caches that should not keep their entries alive on their own.
Related guides
What Is Reference Counting?Reference counting tracks how many references point to an object and frees it automatically when that count d…
What Is Mark and Sweep?Mark and sweep is a garbage collection algorithm that marks all reachable objects, then sweeps away the unmar…
What Is Ownership in Memory Management?Ownership is a model where each resource has a single owning variable responsible for freeing it, making clea…