Java garbage Collection

Source: Internet
Author: User

Steps for Java garbage collection:

    1. Mark (Marking)
The garbage collector marks the objects in the heap, which are still referenced, and which are no longer referenced.
2. Delete (Deleting)Delete objects that are no longer referenced
3. Compression (compacting)Compresses objects that are still being referenced, allowing free heap space to be joined together in order to expedite subsequent space requests
If each time the garbage collector passes through the objects in the heap and compresses the objects that are still in use during the tagging process, it can cause significant time consumption and is obviously not efficient. By observing the life cycle of objects in an application, experience tells us that objects tend to have shorter active times in the heap. As shown in the following:
Therefore, based on the lifetime of the objects in the heap, they are divided into 3 segments: Young Generation, Old Generation, Permanent Generation. Accordingly, the heap space can be represented as shown:
All newly generated objects are stored in the young generation space. When young generation space is full, trigger minor garbage collection. Objects that are not referenced are recycled, and the objects that are still referenced increase their lifetime (age). When their age reaches a certain threshold, they are transferred to the old generation space. The old generation space triggers major garbage collection at the appropriate time for garbage collection. The Permanent generation space stores the metadata (metadata) required by the JVM, describing the classes and methods used by the application. Permanent generation space is reclaimed when the full garbage collection is executed. The reclaimed space includes classes that are no longer used, and so on.
Minor garbage collection and major garbage collection all belong to the "Stop the World" event. That is, when garbage collection occurs, all other application threads are blocked until the garbage collection process ends.
The garbage collection process for young generation space:1. First, all newly generated objects are assigned to the Eden space.
2. When the Eden space is full, minor garbage collection is triggered.
3. The referenced object is moved to the S0 space and the Eden space is emptied
4. At the next minor garbage collection, the referenced objects in Eden are transferred to S1 in S1,s0, and the referenced objects in the S0 have their lifetime increased

5. On the next minor garbage collection, instead, the referenced object is transferred to S0.
6. After a minor garbage collection, if the object in young generation is longer than the threshold, the object is transferred to the old generation (the threshold is 8).


Original: http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/gc01/index.html

Java garbage Collection

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.