Java garbage collection (2) Generational garbage collection of heap memory and java garbage collection

Source: Internet
Author: User

Java garbage collection (2) Generational garbage collection of heap memory and java garbage collection
Heap memory generation collection

Java divides the heap garbage collection into three smaller parts: the new generation, the old generation, and the persistent generation. The new generation mainly uses the replication and tag-clear garbage collection algorithms, while the old generation mainly uses the tag-clear garbage collection algorithms, therefore, java virtual provides different garbage collectors for the new generation and the old generation respectively.

1. Basis for generational recovery:
  • Object survival duration: Most objects are recycled during Young.
  • Different generations adopt different garbage collection policies: For objects with different survival times, different garbage collection algorithms are used to efficiently recycle objects.
2. heap memory generation:
  • Young Generation:

  • Recycling mechanism: because the number of objects is small, stop-and-copy is used for recycling.
  • Composition area: it consists of one Eden area and two vor zones. Two vor zones at the same time are used to save objects, and the other is empty; most newly generated objects are stored in the Eden area. When the Eden area is full, the JVM will trigger the Young GC to recycle the Young generation of garbage because the memory cannot be applied, copy the reachable objects in the from area of movie vor To THE To area, and clear the Eden, From, From, and To areas for interchange, so that the next garbage collection can be performed. Some objects with long survival time are directly allocated to the Old generation (for the long survival time, every Young GC will make the value of the surviving objects in the same vor region + 1 until the threshold value ).
  • Object Source: Most objects are first allocated to the Eden area, and some large objects are directly allocated to the Old generation.
  • Recycling frequency: because most objects in the Young generation quickly enter the inaccessibility statusHigh recovery frequency and fast recovery speed.

  • Old Generation:

  • Recycling mechanism: Mark compression algorithm is used for recycling. (Concurrent-Mark-Sweep)
  • Object Source: larger objects directly enter the Old generation. In addition, reachable objects that have been in the Young for a long time also enter the Old generation.
  • Recycling frequency: because few objects will die, the frequency is not high, and each recycling time is very long, because there are many large objects. A Major GC occurs at least once with a Young GC, which is generally 10 times slower than a Young GC.

  • Permanent generation:

  • Purpose: it is used to load Class, method, and other information. The default value is 64 MB and will not be recycled.
  • Object Source: eg: class files are constantly loaded when classes are dynamically generated, but the occupied memory is not recycled, and the memory of the Permanent generation is exhausted by loading continuously, OOM may occur.
  • Recycling frequency: it will not be recycled.

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.