I am Java EE developer but I don't know where in day to day programming one might use Weak or Soft references.
-
Here is a very good blog post on this very topic: http://weblogs.java.net/blog/2006/05/04/understanding-weak-references I think it will help clear your confusion. – Hunter McMillen Dec 06 '11 at 03:55
-
This SO question will be helpful. [http://stackoverflow.com/questions/299659/what-is-the-difference-between-a-soft-reference-and-a-weak-reference-in-java][1] [1]: http://stackoverflow.com/questions/299659/what-is-the-difference-between-a-soft-reference-and-a-weak-reference-in-java – Upul Bandara Dec 06 '11 at 03:56
2 Answers
You don't not normally use them in day to day programming (at least i don't and i think most of us don't) but they can be very useful!
practical scenarios for me would be:
WeakReference for debugging purpose (e.g. keep track of open database connections).
SoftReference for a quick and dirty cache (e.g. caching large java POJOs that are "expensive" to create and should not be cleaned up immediately).
PhantomReference is really impracticable in my opinion.

- 10,139
- 6
- 45
- 78
There are many good references (nice pun!) and I suggest you Google Bob Lee, "the ghost in the virtual machine."
In a nutshell, a SoftReference is occasionally useful as a quick and dirty cache, but they aren,t that useful. WeakRefences are not for caching, but your listener lists should definitely use them so that unneeded listeners can be garbage collected.

- 15,364
- 7
- 35
- 66