ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  The WeakHashMap Class
Subject:   WeakHashMap shortcomings
Date:   2001-11-14 09:15:34
From:   spruzens
I've found in tests (JDK1.3.1) that WeakHashMap is too agressive at discarding keys for it to be really useful as a cache. WeakReferences tend to get garbage collected as quickly as possible (regardless of memory usage), whereas SoftReferences only seem to get garbage collected when memory is low. The SoftReference behaviour is the one you'd really want for a cache.