JVM garbage collection (tagging-clearing, copying, tagging-sorting, generational) algorithms

Source: Internet
Author: User

1. Tag-Clear Algorithm

Mark Clear algorithm is the most basic collection algorithm , other collection algorithms are based on this idea. The markup cleanup algorithm is divided into "tags" and " Clear the two stages: first mark the objects that need to be recycled, and then unify the clears the object.

Its main disadvantage:①. The marking and purging process is inefficient.

②. After the mark is cleared, a large amount of discontinuous memory fragmentation occurs.

2. Copying Algorithms

It divides the available memory capacity into two blocks of equal size, using only one piece at a time. When this piece is exhausted, copy the surviving object to the other piece, and then remove the memory space that has been used once . In this way, each time it is a piece of memory recovery, no fragmentation and so on, as long as the mobile heap-ordered pointers, in order to allocate memory, simple, efficient operation.

Main drawback: memory is reduced to half the original.

3. Labeling -sorting algorithm

The tag action is consistent with the tag-purge algorithm, and subsequent operations do not just clean the object directly, but instead let all surviving objects move toward one end after cleaning up the useless objects and update the pointers that reference their objects.

The main drawback: on the basis of tag-purge, the object movement is relatively expensive, and the benefit is that it will not produce memory fragmentation.

4, Generational collection algorithm

Divides the memory into several blocks depending on the life cycle of the object. In general, the Java heap is divided into the new generation and the old age, so that according to the characteristics of each era to adopt the most appropriate collection algorithm. In the new generation, each garbage collection is found to have a large number of objects died, only a small number of survival, then choose the replication algorithm, only need to pay a small number of surviving objects copy cost can be completed collection. In the old age, because of the high survival rate of the object and the lack of additional space to guarantee his distribution, it must be recycled using the "mark-and-tidy" algorithm.


JVM garbage collection (tagging-clearing, copying, tagging-sorting, generational) algorithms

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.