As I read the below sample code on wikipedia http://en.wikipedia.org/wiki/Weak_reference
import java.lang.ref.WeakReference;
public class ReferenceTest {
public static void main(String[] args) throws InterruptedException {
WeakReference r = new WeakReference(new String("I'm here"));
WeakReference sr = new WeakReference("I'm here");
System.out.println("before gc: r=" + r.get() + ", static=" + sr.get());
System.gc();
Thread.sleep(100);
// only r.get() becomes null
System.out.println("after gc: r=" + r.get() + ", static=" + sr.get());
}
}
Output before gc: r=I'm here, static=I'm here after gc: r=null, static=I'm here
I am not able to understand the output after gc, where is the strong reference to string referred by sr(WeakReference) to the string in string pool