Skip to content
Latchkey

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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →