Java Virtual machine garbage collection algorithm

Source: Internet
Author: User

1, Mark clear algorithm: First mark out all the objects that need to be recycled, after the mark is complete, all the tagged objects are collected uniformly. The disadvantage is the efficiency problem and the large amount of discontinuous memory fragmentation, which causes the program to allocate large objects at a later time without enough contiguous memory to be found and has to go ahead with another garbage collection action.

2. Copy algorithm: Divide the available memory into two blocks of equal size, use only one of them at a time, and when this piece of memory is used up, copy the surviving objects to the other, then clean up the used memory space once.

3. Labeling algorithm: Let all surviving objects move toward one end, and then directly clean out the memory outside the end boundary.


The current commercial virtual machine garbage collection is a generational collection algorithm: According to the different life cycle of the object to divide the memory into several blocks, generally the Java heap is divided into the new generation and the old age, so you can use the most appropriate collection algorithm according to the characteristics of each era, in the Cenozoic, each garbage collection found that a large number of objects died , only a small amount of survival, then choose the replication algorithm, only a small number of surviving objects can be copied cost to complete the collection. In the old age, because of the high survival rate of the object and the lack of additional space to guarantee it, it must be recycled using either a tag cleanup or a tagging algorithm.

Copyright NOTICE: This article is the original blogger article, reproduced please indicate the source: Http://blog.csdn.net/lingzhm

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.