new WeakReference(String referent, ReferenceQueue q) : WeakReference « java.lang.ref « Java by API






new WeakReference(String referent, ReferenceQueue q)

  

import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;

public class Main {
  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");
      }
    }
  }
}

   
    
  








Related examples in the same category

1.new WeakHashMap()
2.new WeakReference(Object referent)
3.WeakReference: get()
4.WeakReference: isEnqueued()