Last Updated: June 6, 2026
Most Java references you write every day are strong references. A field, a local variable, or an element of a list all hold a strong reference to the object they point at, and as long as the chain of strong references back to a GC root exists, the object stays alive. That's exactly what you want for the cart in front of the customer or the order being processed right now. It's the wrong behavior for a cache that should give up its entries when memory is tight, or a map of session data that should not keep a logged-out customer pinned in the heap forever. The java.lang.ref package gives you three weaker reference types (SoftReference, WeakReference, PhantomReference) and a queue mechanism (ReferenceQueue) for noticing when the garbage collector reclaims them. This lesson covers all of them, the reachability strength hierarchy that ties them together, the WeakHashMap collection that uses weak references internally, and the modern Cleaner API that has replaced finalize() for post-mortem cleanup.
Reference types are the missing piece between "the GC could collect this if nothing held it" and "I want some control over how aggressively the GC collects it." Understanding them is what lets you build a product image cache that yields under memory pressure, a customer session map whose entries disappear when the session key is gone, and a wrapper around an off-heap byte buffer that gets cleaned up without ever using finalize.