Skip to main content
PreparationZone Logo
PreparationZone
Back to Java

Java · Hard · Pro

WeakHashMap and weak references — cache key eviction?

JavaCollectionsStaff
Model answerPreview

WeakHashMap

WeakHashMap holds keys via weak references—when the key object is only weakly reachable, GC can reclaim it and the entry disappears. Used for canonicalization caches tied to object lifetime (class loaders,…