JDK-6423502 : (coll) Add value-weak version of WeakHashMap
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 5.0
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-05-09
  • Updated: 2012-10-08
  • Resolved: 2010-12-28
Related Reports
Duplicate :  
Relates :  
Description
A DESCRIPTION OF THE REQUEST :
In order to model a cache, it is quite useful to have a class similar to WeakHashMap. But, in my opinion, this class is designed wrong. It should not reference the keys by WeakReferences, but the values.

An example:

Imagine a cache for images. A quite useful model would be a map, where you put image values with key-reference by their pathname (HashMap<String, Image>)
So, if an image is not references anywhere, it could be deleted (and garbage collected) from the cache and reloaded if needed again afterwards.

The class WeakHashMap is NOT useful for this kind of behaviour, since it weakly references the keys, which would be the pathname in this example. But the keys in any cachmodel are always known and present; its the values you want to cache (and maybe remove if not used).

JUSTIFICATION :
Caching is very important and widely used in many programs.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
maybe a whole cache package would be nice with different kind of caches, not only a memory-based one
ACTUAL -
see description

CUSTOMER SUBMITTED WORKAROUND :
write your own cache

Comments
EVALUATION Looks like a dup of the ancient 4175502: (coll) java.util: Add WeakValueHashMap class
09-05-2006