JVM Memory Management: GC algorithm refinement (five minutes to give you a thorough understanding of the mark/Purge algorithm)

Source: Internet
Author: User
Tags garbage collection thread

First, we recall the root search algorithm mentioned in the previous chapter, which solves the problem of which objects we should recycle, but it obviously does not have the burden of garbage collection, because we want to do garbage collection while the program is running (the Java program that we run on the JVM). You must let the GC thread and the thread in the program to cooperate with each other in order to not affect the operation of the program under the premise of smooth garbage recycling.

To achieve this goal, the tag/purge algorithm came into being. It does this by stopping the entire program (also being the Stop the world) when the available memory space in the heap is depleted (available memory), and then doing two things, the first is the tag and the second is clear.

The following LZ specific explanation of the mark and clear what will be done.

Clear: The purge process traverses all objects in the heap and clears all objects that are not marked.

In fact, these two steps are not particularly complicated and easy to understand. LZ in layman's words explain the mark/purge algorithm, when the program is running, if the available memory is depleted, the GC thread is triggered and paused, then the surviving object is marked again, then all the objects that are not marked in the heap are eliminated, and then the program resumes operation.

The following LZ gives you a set of pictures describing the above process, combined with pictures, we have to visually look at this process, first is the first picture.

This diagram represents the state of all objects during the run of the program. Their flag bits are all 0 (that is, unmarked, the following default 0 is unmarked, 1 is marked), assuming that the effective memory space is exhausted at the moment, the JVM will stop running the application and open the GC thread, and then start marking work. Following the root search algorithm, after marking, the status of the object is shown below.

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.