SoftReferences are deleted when memory is low.
WeakReferences are cleared more often (for example, all the time when the object has only weak links)
Check out the extraclass Java document for the package (package documentation is useful for explanation): http://download.oracle.com/javase/1.5.0/docs/api/java/lang/ref/package-summary.html
Can you specify the exact message that you see with Tomcat at shutdown? Are you sure you are not mistaken? For Tomcat, itβs important that there are no hard links that bind ClassLoader to ServletContext.
Re WeakHashMap: http://download.oracle.com/javase/1.5.0/docs/api/java/util/WeakHashMap.html Only keys are weakly held. What do you use as a "value"? Does the value self-determine its "key"? In this regard, I wonder what WeakHashMap gives you (this assumes that this is the right tool for the job).
In my experience, you can get WeakReferences with Sun JVM 5, which will be cleared using System.gc (), 100% reliable for me when I first start GC. But they do not guarantee this.
source share