You can keep track of every class ever loaded in your JVM. I was just wondering if you can do the same for every object ever instantiated?
If you need it for profiling check JFluid (http://research.sun.com/projects/jfluid)? It is an experimental tool that uses dynamic bytecode instrumentation. There is version 1.4 two days ago. It uses modified 1.4.2 HotSpot JVM, so you must download the tool and JDK (but there are jvm.dll’s only, to patch your existing 1.4.2 VM).
nonono not for profiling. Part of the application.
The debugger interfaces to the JVM make doing this as part of a profiler pretty easy, but I think that’s more effort than you’d want to go through for general app design.
I should have been more clear in my question :).
I also have a nasty feeling I’ve asked this here before, which is how I found out about the curretn state-of-art in debugger interfaces. Oops. Shouldn’t start new posts whilst half asleep…
There is no generic way to do it but you can make one by subclassing Object and creating a TrackedObject abstract base class.
You would then use a WeakHashMap to store and update an Integer count by Class, updated in the constructor of TrackedObject. You would then also need a reference queue to detect when they get collected, and use this to decrement the counter.
Cas 
Actually you can open the JVMPI inteface and “be your own profiler.”
The only caveat is that JVMPI does slow execution somewhat.