In pure Java, no. Java has no way to peer into the memory without proper references. There is also a problem with counting the number of objects there are in this manner:

When an object gets...