Code example for PhantomReference

Methods: sleep

		 * meant to be used to access the object, but as a signal that the 
		 * object has already been finalized, and the garbage collector is 
		 * ready to reclaim its memory. 
		final ReferenceQueue<Stuff> queue = new ReferenceQueue<Stuff>();
		PhantomReference<Stuff> phantomS = new PhantomReference<Stuff>(instantiateStuff("Phantom Reachable"), queue);
		 * I found the object is not enqueued unless I remove the override 
		 * finalize() method from Stuff class. 
		 * But why??? 
		new Thread(new Runnable() {
			public void run() { 
				try { 
					System.out.println("Awaiting for GC");
					PhantomReference<Stuff> ref = (PhantomReference<Stuff>) queue.remove();
					System.out.println("Stuff has been enqueued!");
				} catch (InterruptedException e) {
		System.out.println("Invoking GC");
Stop searching for code, let great code find you!  Add Codota to your java IDE