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

2

11

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

Empennage answered 25/9, 2014 at 18:56 Comment(0)
M
12

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.

Madaih answered 27/9, 2014 at 6:25 Comment(1)
How to reach "instances view" ? At first take a heap dump (right-click on your application in the left panel, then "Heap dump") then 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.Rawlinson
A
0

You can get Retained and Shallow size. Differences see there https://www.yourkit.com/docs/java/help/sizes.jsp
*) To get "Retained size" jvisulVM->the "monitor" tab->the "heap dump" tab->go to the created heapdump->click on it "OQL Console"-> and in the bottom of it "Query editor" write your OQL sql for example to find the String with the val "GHT" the query will be select s from java.lang.String s where s.toString().equals("GHT")->click "execute"->and in the query result click by needed reference->you can see there information about your instance and you can click there "Compute retained size" to get that you want
*) To get the "Shallow" size jvisulVM->the "monitor" tab->the "heap dump" tab->go to the created heapdump->click on it "OQL Console"-> and in the bottom of it "Query editor" write your OQL sql for example to find the String with the val "GHT" the query will be select sizeof(s) from java.lang.String s where s.toString().equals("GHT")->click "execute"->you will see your object size in bytes
More verbose you can read about it here "Shallow" https://blogs.oracle.com/sundararajan/querying-java-heap-with-oql

Apogee answered 25/7, 2019 at 13:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.