JAVA Shallow heap & amp; Retained heap, javashallowheap

Source: Internet
Author: User

JAVA Shallow heap & Retained heap, javashallowheap

I recently studied the memory leakage problem and found Shallow heap & Retained heap in the MAT tool.

Then I found some information on the Internet.

 

Shallow Size 
The memory size occupied by the object itself, excluding the objects referenced by the object.
For non-array objects, its size is the sum of the size of the object and all its member variables. Of course, there will also be some data storage units with java language features.
For an array object, its size is the total size of the array element object.

Retained Size 
Retained Size = Current object Size + total Size of objects that can be directly or indirectly referenced by the current object. (Meaning of indirect reference: A-> B-> C, C is indirect reference)
In other words, the Retained Size is the total memory that can be released from the Heap after the current object is GC.
However, objects directly or indirectly referenced by GC Roots must be excluded during release. They will not be treated as Garbage for the moment.

Retained Size 

 

.

Retained Size of object A = Shallow Size of object
Retained Size of object B = Shallow Size of object B + Shallow Size of Object C

The D object is not included here, because the D object is directly referenced by GC Roots. 
What if GC Roots does not reference the D object?

 


At this time,
Retained Size of object B = Shallow Size of object B + Shallow Size of Object C + Shallow Size of object D

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.