Java garbage Collection (ii) Generational collection of heap memory

Source: Internet
Author: User

Generational recycling of heap memory

Java garbage collection for heaps divides the heap into three smaller parts: The new generation, the old age, and the enduring generation. The new generation mainly uses the replication and labeling-clearing garbage collection algorithm, the old generation mainly uses the tag-sorting garbage collection algorithm, so Java virtual in the new generation and older generations to provide a variety of different garbage collectors.

1. The basis of generational recovery:
    • object Life span : Most objects are recycled during young.
    • Different generations adopt different garbage collection strategies : Classify objects with different survival time, and use different garbage collection algorithms for efficient recycling.
2. Generation of heap Memory:
    • Young Generation :

  • Recycling mechanism: Replication (stop-and-copy) is used for recycling because of the small number of objects.
  • Composition area: Consists of 1 Eden and 2 survivor districts, two survivor zones at the same time, one for saving objects, the other is empty; most of the newly generated objects are placed in the Eden area, and when the Eden area is full, the JVM will trigger the GC, for Young's garbage collection, copies the survivor from the from area to the to area, and then clears the Eden, from zone, from zone, and to zone interchange to perform the next garbage collection. Some long-lived objects are assigned directly to the old generation (for the duration of the lifetime, each young GC causes the survivor to survive the value +1 until the threshold).
  • Object Source: Most objects are first assigned to the Eden area, and some large objects are assigned directly to the old generation.
  • Recovery frequency: Because most of the objects in Young's generation quickly enter the unreachable state, the recovery frequency is high and the recovery rate is fast.

  • Old generation:

  • Recycling mechanism: Using the tag compression algorithm to recover. (Concurrent-mark–sweep)
  • Object Source: The larger object will go straight to the old generation, and the long-lived objects that survive in young can also enter the old generation.
  • Recovery frequency: Because very few objects will die, so the frequency is not high, and the time of each recovery is very long, because there are more large objects. A Major GC occurs at least once with a young GC, which is typically 10 times times slower than the young GC.

  • Permanent generation:

  • Purpose: Used to load class, method and other information, the default is 64M, will not be recycled.
  • Object source: Eg: dynamically generated classes, the dynamic loading of class files, but these occupied memory will not be recycled, the constant load will let permanent generation of memory exhaustion, will appear oom phenomenon.
  • Recovery frequency: Will not be recycled.

Java garbage Collection (ii) Generational collection of heap memory

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.