Java heap problem analysis (not finished)

Source: Internet
Author: User

The difference between a shallow heap and a retained heap

1 Shallow size

Is the size of the memory occupied by the object itself, and does not contain the object it references. The shadow size for a regular object (not an array) is determined by the number and type of its member variables, while the shallow size of the array is the sum of the size of the array elements.

2 retained size

Retained size= the current object size + the sum of the size of the object to which the current object can be directly or indirectly referenced. (Meaning of indirect reference: A->b->c,c is an indirect reference) and excludes objects that are referenced directly or indirectly by GC roots

In other words, retained size is the amount of memory that the current object can be freed from the heap after it is GC.
However, when you release it, you also exclude objects that are referenced directly or indirectly by GC roots. They will not be treated as garbage for the time being.

GC roots directly references A and B two objects.

The shallow Size of the retained Size=a object of the A object
The retained of the B object is the shallow size of the shallow size + C object of the Size=b object.

Chestnuts??

The retained size of the obj1 is Obj1, obj2, obj4 the sum of shallow size, and does not include OBJ3 's shallow size, because OBJ3 is referenced by GC roots, which means obj3 is referenced in addition to OBJ2, There are other external references as well.

The retained size in obj1 is the sum of the obj3 size for obj1, Obj2, Obj4, Shallow, because OBJ3 has no other external references other than the OBJ2 reference.

Excerpt from: http://blog.csdn.net/a740169405/article/details/53610689

Java heap problem analysis (not finished)

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.