Garbage collection algorithm

Source: Internet
Author: User
Mark-sweep algorithm

The tag-purge (Mark-sweep) algorithm is divided into two phases: Mark and purge, which mark all objects that need to be recycled, and then uniformly reclaim all the tagged objects after the tag is complete. This algorithm mainly has two disadvantages: 1. The mark and purge process is less efficient 2. A large number of discontinuous memory fragments are generated after the tag is purged. Because of the excessive space fragmentation, it is possible that the program will not be able to find enough contiguous memory space when it needs to allocate large objects during the run, causing another garbage collection action to be violated.

Coping algorithm

The replication algorithm 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 is already used is cleaned out once. Coping algorithm is only a piece of memory recovery, memory allocation without considering the problem of memory fragmentation, the implementation of simple, efficient operation. The cost of this algorithm is to reduce the memory to the original half, the space use efficiency is not high.

Mark-compact algorithm

The high survival rate of the replication algorithm is that many replication operations are performed and the efficiency becomes low. In the old age of the object general life cycle is relatively long, generally not suitable for the use of replication algorithm. According to the survival characteristics of the old-age object, the "Mark-Organize" (mark-compact) algorithm emerges. The tagging process for the mark-compact algorithm is the same as the mark-sweep algorithm, but the next step is not to reclaim the object directly, but to let the surviving object move toward one end and then clean out the memory outside the end boundary.

Bibliography:

"In-depth understanding of Java Virtual machines: JVM advanced features and best practices"

"Deep Java Virtual machine"

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.