Java Virtual machine-garbage collection algorithm

Source: Internet
Author: User

This paper mainly introduces the garbage collection algorithm of Java Virtual machine.

I. Overview

second, mark-Clear algorithm

Mark-sweep. Like a name, the algorithm is divided into two steps:

    1. Tags: objects that need to be recycled at the mark
    2. Clear: The Tagged object is reclaimed uniformly after the tag is complete.

Disadvantages:

    1. Efficiency issues: The efficiency of labeling and purging is not high
    2. Space problem: A large number of discontinuous memory fragments are generated after the tag is cleared
third, the replication algorithm

The replication algorithm is an optimization of the tag cleanup, which divides the memory on the heap into two equal-sized areas, one for the idle area and one for the active area. In the program run, the actual use of the active area, that is, 50% of the space is wasted

Implementation process:

    1. Find all the surviving objects in the active space.
    2. Copy these surviving objects to an idle area.
    3. The previous activity space is emptied and then becomes free space, and the area where the surviving object resides becomes the active space.

Advantage, after the memory is collected, there is a large amount of contiguous free space.

Disadvantage, 50% of the memory space is placed, only in the event of memory recycling, the GC will borrow the idle area to achieve memory recovery work.

Iv. marking-finishing 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.

five, generation of collection algorithm

Divide the Java heap into the new generation and the old age:

    1. New belt: Each time there will be a large number of objects die, only a small number of survival, select the replication algorithm, only a small number of surviving objects to replicate, replication cost is low.
    2. Old age: The old age has a high survival rate and is recycled using the mark-sweep or tag-grooming algorithm.

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.