Garbage collection algorithm

Source: Internet
Author: User

Found the "Junk" object, how to mark "garbage" object?

Tag-Purge algorithm

All objects that need to be reclaimed are marked, and the tagged objects are collected uniformly after the mark is complete. (most basic algorithm, other algorithms improved on the basis of this algorithm) disadvantage: the efficiency of marking and purging is not high, and the mark and purge will result in a lot of memory fragmentation (space problem) Replication AlgorithmsDivide the memory by the capacity of two blocks of equal size, one at a time, when the piece is finished, copy the surviving object to another piece of memory, then reclaim the memory that has been used, and empty the memory space once. Features: Simple and efficient disadvantage: the memory shrinks to the original half of the modern commercial virtual machines use replication algorithms to reclaim the new generation. Because of the new generation of objects around 98% are "dying", so you can not divide the memory according to 1:1, but divide the memory into a large Eden space and two small survivor space. Each time you use Eden and one of the survivor regions (from), when recycled, the surviving objects from the Eden and from zones are copied to another survivor (to), and then the space from the Eden and from areas are cleared. If there is not enough space in the to area after recycling, additional memory areas (older years) are required for allocation to be guaranteed. The ratio of the Eden and Survivor districts is 8:1 by default. tagging-sorting algorithmsThe disadvantage of the replication algorithm is that in the case of high object survival, the need to replicate the more right objects, the efficiency will be lower, and waste space, so for the old age, do not use this algorithm. The mark-and-organize algorithm marks all objects first, and finally all surviving objects move toward one end, and then clear the space outside the end boundary. Generational Collection AlgorithmsThe current commercial virtual machines are using "generational collection" algorithm, according to different generations of different tagging algorithms, according to the life cycle of the object will be divided into different blocks of heap memory, Java heap is generally divided into the new generation and the old age, the new generation of the use of replication algorithm, the old age using "mark-clear" or "mark-collation" algorithm Reference: "In-depth understanding of Java Virtual machines: JVM Advanced features and practices" 2018-07-25 17:15:28

Garbage collection algorithm

Related Article

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.