title: Java's WeakHashMap and caching: Why is it referencing the keys, not the values?
body: <p>Java's <a href="http://developer.android.com/reference/java/util/WeakHashMap.html" rel="noreferrer">WeakHashMap</a> is often cited as being useful for caching. It seems odd though that its weak references are defined in terms of the map's keys, not its values. I mean, it's the values I want to cache, and which I want to get garbage collected once no-one else besides the cache is strongly referencing them, no?</p>
  
  <p>In which way does it help to hold weak references to the keys? If you do a <code>ExpensiveObject o = weakHashMap.get("some_key")</code>, then I want the cache to hold on to 'o' until the caller doesn't hold the strong reference anymore, and I don't care at all about the string object "some_key".</p>
  
  <p>Am I missing something?</p>