List of usage examples for java.lang.ref ReferenceQueue remove
public Reference<? extends T> remove() throws InterruptedException
From source file:Main.java
public static void main(String[] argv) throws Exception { ReferenceQueue rq = new ReferenceQueue(); WeakReference<String> wr = new WeakReference<String>("string", rq); while (true) { Reference r = rq.remove(); if (r == wr) { System.out.println("no longer referenced"); }// w ww.j av a 2 s. c o m } }
From source file:Main.java
public static void main(String[] argv) throws Exception { ReferenceQueue rq = new ReferenceQueue(); PhantomReference<String> pr = new PhantomReference<String>("object", rq); while (true) { Reference r = rq.remove(); if (r == pr) { // about to be reclaimed. r.clear();/*w w w. ja v a 2 s .com*/ } } }