Can someone explain the difference between the three Reference classes (or post a link to a nice explanation)? SoftReference > WeakReference >
SoftReference
WeakReference
String str = new String("hello, world"); WeakReference ref = new WeakReference(str); str = null; if (ref != null) { System.gc(); System.out.println(ref.get()); }
In this case, it will output null. The call to System.gc() is important here.
System.gc()