Reputation: 2169
The objects in java are stored in the heap. Within my Java program I need code that does this task:
At a given moment, how can I list all the objects existing in the heap?
List<Object> listOfObjectsInHeap = ... ?
Upvotes: 0
Views: 739
Reputation: 4044
The JVM provides an interface, called JVMTI, that can be used for this purpose. Originally meant to connect profiling tools, it also can be abused for your purpose, also from inside your program.
https://docs.oracle.com/javase/8/docs/platform/jvmti/jvmti.html
Upvotes: 1