// Path: src/main/java/com/tantaman/commons/gc/GCNotifier.java
// public class GCNotifier {
// 	private final ReferenceQueue<Object> refQueue;
// 	private final ExecutorService notificationExec;
// 	// have to hold the weak refs so they don't get GC'ed.
// 	// if the weak refs are GC'ed, then we don't get notified
// 	// about the GC of whatever they are referencing.
// 	private final Map<Reference<?>, Object> refs;
// 	private static final Object NOTHING = new Object();
// 	
// 	public GCNotifier() {
// 		refQueue = new ReferenceQueue<Object>();
// 		notificationExec = Executors.newFixedThreadPool(1, new NamedThreadFactory(GCNotifier.class.getSimpleName()));
// 		refs = new ConcurrentHashMap<Reference<?>, Object>();
// 		
// 		notificationExec.execute(new Runnable() {
// 			@Override
// 			public void run() {
// 				while (!Thread.interrupted()) {
// 					try {
// 						KeyedWeakReference<Listener, Object> ref = (KeyedWeakReference<Listener, Object>)refQueue.remove();
// 						refs.remove(ref);
// 						ref.getKey().objectCollected();
// 					} catch (InterruptedException e) {
// 						break;
// 					}
// 				}
// 			}
// 		});
// 	}
// 	
// 	public void register(Listener listener, Object object) {
// 		KeyedWeakReference<Listener, Object> ref = new KeyedWeakReference<Listener, Object>(listener, object, refQueue);
// 		refs.put(ref, NOTHING);
// 	}
// 	
// 	public static interface Listener {
// 		public void objectCollected();
// 	}
// }


import com.tantaman.commons.gc.GCNotifier;
package com.tantaman.commons.examples;


/**
 * The GCNotifier allows you to be notified when an object is garbage collected
 * but without using a finalizer.
 * @author tantaman
 *
 */
public class GCNotifierDemo {
	public static void main(String[] args) {
// Path: src/main/java/com/tantaman/commons/gc/GCNotifier.java
// public class GCNotifier {
// 	private final ReferenceQueue<Object> refQueue;
// 	private final ExecutorService notificationExec;
// 	// have to hold the weak refs so they don't get GC'ed.
// 	// if the weak refs are GC'ed, then we don't get notified
// 	// about the GC of whatever they are referencing.
// 	private final Map<Reference<?>, Object> refs;
// 	private static final Object NOTHING = new Object();
// 	
// 	public GCNotifier() {
// 		refQueue = new ReferenceQueue<Object>();
// 		notificationExec = Executors.newFixedThreadPool(1, new NamedThreadFactory(GCNotifier.class.getSimpleName()));
// 		refs = new ConcurrentHashMap<Reference<?>, Object>();
// 		
// 		notificationExec.execute(new Runnable() {
// 			@Override
// 			public void run() {
// 				while (!Thread.interrupted()) {
// 					try {
// 						KeyedWeakReference<Listener, Object> ref = (KeyedWeakReference<Listener, Object>)refQueue.remove();
// 						refs.remove(ref);
// 						ref.getKey().objectCollected();
// 					} catch (InterruptedException e) {
// 						break;
// 					}
// 				}
// 			}
// 		});
// 	}
// 	
// 	public void register(Listener listener, Object object) {
// 		KeyedWeakReference<Listener, Object> ref = new KeyedWeakReference<Listener, Object>(listener, object, refQueue);
// 		refs.put(ref, NOTHING);
// 	}
// 	
// 	public static interface Listener {
// 		public void objectCollected();
// 	}
// }


// Path: src/examples/java/com/tantaman/commons/examples/GCNotifierDemo.java
import com.tantaman.commons.gc.GCNotifier;

package com.tantaman.commons.examples;


/**
 * The GCNotifier allows you to be notified when an object is garbage collected
 * but without using a finalizer.
 * @author tantaman
 *
 */
public class GCNotifierDemo {
	public static void main(String[] args) {
		GCNotifier notifier = new GCNotifier();