Is it possible to get the object reference count?

From your description, it seems you care less about the actual count of references than to simply know when an object has been collected. If this is the case, you can use WeakReference or PhantomReference to determine when a referenced object is ready for finalization.

See:

  • Javadoc for WeakReference: http://download.oracle.com/javase/6/docs/api/java/lang/ref/WeakReference.html
  • Javadoc for PhantomReference: http://download.oracle.com/javase/6/docs/api/java/lang/ref/PhantomReference.html
  • A great explanation of weak references: https://community.oracle.com/blogs/enicholas/2006/05/04/understanding-weak-references
  • Garbage collector callbacks: http://java.dzone.com/articles/letting-garbage-collector-do-c
  • Garbage collection notification?

Java doesn't offer this option natively as far as I know.

Here you have some guidance on how to do it manually:

http://www.velocityreviews.com/forums/t363649-how-do-i-get-a-reference-count-of-a-object-in-java.html