Code example for WeakReference

Methods: clearget

0
	 */ 
	public void test_clear() { 
		tmpA = new Object();
		tmpB = new Object();
		SoftReference sr = new SoftReference(tmpA, new ReferenceQueue());
		WeakReference wr = new WeakReference(tmpB, new ReferenceQueue());
		assertTrue("Start: Object not cleared.", (sr.get() != null)
				&& (wr.get() != null));
		sr.clear();
		wr.clear();
		assertTrue("End: Object cleared.", (sr.get() == null)
				&& (wr.get() == null));
		// Must reference tmpA and tmpB so the jit does not optimize them away 
		assertTrue("should always pass", tmpA != sr.get() && tmpB != wr.get());
	} 
 
	/** 
	 * @tests java.lang.ref.Reference#enqueue() 
	 */ 
	public void test_enqueue() { 
		ReferenceQueue rq = new ReferenceQueue();