JVM memory management ------ GC algorithm (five minutes to teach you the ultimate algorithm-generation collection algorithm)

Source: Internet
Author: User

The generational collection algorithm is not so much the fourth algorithm as the actual application of the first three algorithms..

Dead object: The objects that are born and run out on Thursday are the objects that will die soon after they become active.

Example: Local variables of a method, temporary variables in the cycle, and so on.

Old object: This type of object generally lives for a long time, and the age is too old to die, but in the final analysis, the old object will almost die sooner or later, but it is just almost the same.

Example: Cache object, database connection object, singleton object (Singleton mode), and so on.

Destroy object: Such objects will almost never die once they are born, and they will almost never die forever. Remember, they are almost never killed.

Example: Objects in the String pool (metadata mode), loaded class information, and so on.

Both the dead object and the old object are in the JAVA heap, but the dead object is in the method area..

The generational collection algorithm is designed for JAVA heap, that is, for dead objects and old objects..

Dead object: Do you still remember the requirements for using the replication algorithm for these objects because they have a short survival time? That is, the object survival rate cannot be too high, soDead objects are the most suitable for Using Replication Algorithms..

The first point is to use this method. We only waste 10% of the memory, which is acceptable because we get the memory neatly arranged and GC speed. The second point is that the premise of this policy is that the memory occupied by each surviving object cannot exceed the size of 10%. Once the memory occupied by each surviving object is exceeded, the extra objects cannot be copied..

Called the new generation or young generation. The remaining part is calledElder Generation.

Old object: The survival rate of such objects is very high, because most of them are transferred from the new generation. Just like a person, a person who has lived for a long time will become an old man.

1,Every object in the new generation hasAge

2,When the memory occupied by the new generation of surviving objects exceeds 10%, the excess objects are placed in the old generation. In this case, the old generation is the "backup warehouse" of the new generation ".

The old object can only use the tag/sort or tag/clear algorithm..

Permanent generation,Is it an appropriate name?

 

General GC (minor GC): Only GC for the new generation region.

Global GC (major GC or Full GC): GC for the old generation, occasionally accompanied by GC for the new generation and GC for the permanent generation.

 

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.