Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

visualvm

oql

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

like image 986
Jack Avatar asked Sep 25 '14 18:09

Jack


People also ask

How can we find the actual size of an object on the heap?

One way to get an estimate of an object's size in Java is to use getObjectSize(Object) method of the Instrumentation interface introduced in Java 5. As we could see in Javadoc documentation, the method provides “implementation-specific approximation” of the specified object's size.

How do you analyze a heap dump in JVisualVM?

If you have a heap dump file saved on your local system, you can open the file in Java VisualVM by choosing File > Load from the main menu. Java VisualVM can open heap dumps saved in the . hprof file format. When you open a saved heap dump, the heap dump opens as a tab in the main window.

How do I monitor VisualVM?

Under the Local node in the Applications window, right-click the application node and choose Open to open the application tab. Click the Profiler tab in the application tab. Click Memory or CPU in the Profiler tab. When you choose a profiling task, VisualVM displays the profiling data in the Profiler tab.

What is retained size in heap dump?

Retained heap is the amount of memory that will be freed when the particular object is garbage collected. Thus, retained heap size of B is 30 bytes.


1 Answers

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.

like image 94
Tomas Hurka Avatar answered Nov 15 '22 20:11

Tomas Hurka