ReferenceQueue q = new ReferenceQueue();
Reference ar = new WeakReference(a);
Reference br = new WeakReference(b, q);
Reference cr = new WeakReference(c, q);
Reference dr = new PhantomReference(d, q);
Reference er = new MyReference(e, q, "foo");
WeakHashMap<Key,Object> map = new WeakHashMap();
map.put(new Key("foo"), f);
a = b = c = d = e = cr = null;
System.out.println("a: " + ar.get());
System.out.println("b: " + br.get());
System.out.println("d: " + dr.get());
System.out.println("e: " + er.get());
System.out.println("f: " + map.get(new Key("foo")));
System.gc();
System.out.println("a: " + ar.get());
System.out.println("b: " + br.get());
System.out.println("d: " + dr.get());
System.out.println("e: " + er.get());
System.out.println("f: " + map.get(new Key("foo")));
for (Reference r = q.poll(); r != null; r = q.poll()) {
System.out.println("polled: " + r.get());