Oussama ZAGHDOUD
Oussama ZAGHDOUD

Reputation: 2169

List all objects ( instances ) created in the JVM Heap

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

Answers (1)

tquadrat
tquadrat

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

Related Questions