If you create a new object in Java, you have a strong reference. e.g. Strong Ref above. GC will never reclaim this object because you have a strong reference to it.
For weak and soft references, the GC may reclaim the object under certain conditions. A "soft reference" is an object that has a pointer: the pointer may or may not be null.
The difference between soft and weak is subtle. Soft references are easier to understand. The GC will reclaim objects that are "soft reachable" when it gets low on memory. A good example is a memory-sensitive cache where you want to keep some stuff, but it's ok if the GC reclaims it. In the past, I have written a map that uses SoftReferences. (There may also be something similar in Jakarta Commons.) The idea is:
Note that in the above, the SoftReference will stay in the map, but the object pointed to by the soft reference may "disappear" due to GC.
Weak references are somewhat similar but I'll leave it to the docs to explain "weak" versus "soft". Phantom references are intended for the internal workings of the GC and are not appropriate for application development.
[ May 13, 2007: Message edited by: M Easter ]
[ May 13, 2007: Message edited by: M Easter ] [ May 13, 2007: Message edited by: M Easter ]