Java Garbage Collection Overview

Source: Internet
Author: User

The GC solves three major problems:

    • What memory needs to be recycled?
    • When do I recycle?
    • How to recycle?

What memory needs to be recycled?

The simplest is the reference count (reference count), and the flaw is that the circular reference cannot be resolved. The faster algorithm is the accessibility analysis (reachable).

When do I recycle?

At least two marking processes to go through:

    1. After the accessibility analysis, it was found that no reference chain connected to GC roots was first flagged and filtered--whether it was necessary to perform finalize ().
      • Object does not have a finalize () method or is executed by the virtual machine, as "No need to execute"
      • It is necessary to perform finalize (), be placed in the F-queue queue, and then "execute" (triggering the corresponding method, but not waiting for it to be completed) at a later time by the finalizer thread (the virtual machine automatically establishes a low priority).
    2. The GC then marks the second small size of the objects in the F-queue.

How to recycle?

    1. Mark-sweep (Mark-Clear): (defect: Causes a large amount of memory fragmentation.) )
    2. Copy: The memory is divided into two, using only half of them at a time. When you clean up, copy the surviving object to the unused half, and then clean up the half that is used. (Defect: Reduces memory to half the original, and is inefficient in the case of many surviving objects.) So this algorithm is used in the Cenozoic region, a chunk of Eden and two blocks of survivor area. Each time you use Eden and one of the survivor areas. )
    3. Mark-compact (Marker-collation): Let all surviving objects move toward one end, suitable for areas with more inventory objects, such as the Laosheng generation.
    4. Generational collection: All of the above methods are combined to use different algorithms for different generation regions.

Reference Documents :

    • Java garbage Collection (GC) mechanism detailed
    • "Thinking in Java"
    • "In-depth understanding of Java virtual machines"

Java Garbage Collection Overview

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.