Currently I use a HashMap<Class, Set<Entry>>, which may contain several millions of short-lived and long-lived objects. (Entry is a wrapper class around an Object and an integer, which is a duplicate count).
I figured: these Objects are all stored in the JVM's Heap. Then my question popped in my mind; instead of allocating huge amounts of memory for the HashMap, can it be done better (less memory consumption)?
Is there a way to access Objects in the Java Heap indirectly, based on the Class of the Objects?
With "indirectly" I mean: without having a pointer to the Object. With "access" I mean: to retrieve a pointer to the Object in the heap.