A step-by-step study of jvm-garbage collection algorithm

Source: Internet
Author: User

Tag-Purge algorithm

The algorithm is divided into two phases: marking and purging, first marking all objects that need to be recycled, and then uniformly reclaiming all tagged objects after the tag is complete.

Disadvantages of this algorithm:

1, efficiency issues: marking and clearing two processes are not efficient

2. Space problem: After the mark is cleared, there will be a lot of discontinuous memory fragmentation, too much memory fragmentation may be the later when the program is running, you need to allocate large objects, you cannot find enough contiguous memory and have to trigger another garbage collection in advance.

Replication Algorithms

In order to solve the problem of recycling efficiency, the replication algorithm is introduced. It divides the available memory by capacity into two blocks of equal size, using only one piece at a time. When this piece of memory is used up, the surviving object is copied to the other piece, and then the memory space that has been used is cleaned out once. In this way, each collection recycles the entire half of the area, regardless of the complexity of the memory fragments, just move the heap pointers and allocate the memory sequentially.

Disadvantages:

The cost of this algorithm is to reduce the memory to half the original, wasting space.

A more detailed explanation of the replication algorithm can be found in: Talk about the younger generation of the JVM

Tagging-sorting algorithms

The replication algorithm is suitable for low-survival algorithms in the Cenozoic. But for this region of the old age, efficiency will be lower. So in the old years, the general use of marker-collation algorithm

Tag-the markup and markup in the algorithm-the same as the markup in the cleanup, but the grooming step is not to clean up the tagged object directly, but to let all surviving objects move toward one end and then clean out the memory outside the boundary.

Generational collection Algorithms

The Generational collection algorithm divides memory into extremely fast based on the lifetime of the object. In general, the Java heap is divided into the new generation and the old age, so that you can use the most appropriate collection algorithm according to the characteristics of each age. In the new generation, the replication algorithm is used to recycle the "mark-clean" algorithm or the "mark-tidy" algorithm in the old age.

A step-by-step study of jvm-garbage collection algorithm

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.