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
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With