javavisualvmoql

VisualVM: how to find size of object in heap including all the objects it references from its fields?


how do I find size of object in heap including all the objects it references from its fields?

In the Classes view under heap dump, the size only indicates the "shallow" size of object. I would like to know transitively what the size of the object is, basically the total size of objects that it references through fields.

thanks


Solution

  • Take a heap dump (right-click on your application in the left panel, then "Heap dump")

    Double-click on the class of your choice in "Classes" tab and it will open the "instances" tab for this class.

    Finally click on "Compute Retained Sizes" on top-right corner of the tab.