Last Updated: May 22, 2026
A weak reference lets you hold a reference to an object without preventing the garbage collector from reclaiming it. The usual reference you write, Product p = new Product(...), is a strong reference, and as long as it's reachable from the root set, the GC won't collect the object behind it. There are cases where that's the wrong behavior: a cache that should let entries go when memory gets tight, an event subscription that shouldn't keep a long-dead subscriber alive, a sidecar dictionary of debug metadata that shouldn't extend the lifetime of the objects it describes. This lesson covers WeakReference<T>, its non-generic cousin, and ConditionalWeakTable<TKey, TValue>.