GC Memory Recovery mechanism

Source: Internet
Author: User

Determine which objects can be recycled

GC is based on whether the object survives to determine whether or not to recycle, there are two main algorithms to determine whether the object is alive: Reference counting algorithm, accessibility analysis algorithm

Reference counting algorithm

The principle of reference counting is to add a reference counter to the object, each quoted counter plus 1, the reference fails minus 1, when the counter 0 indicates that the object is not referenced, Can be recycled, the reference counting method is simple and efficient, but there is a circular reference problem between objects, which may lead to the inability to be recycled by GC , and it takes a lot of effort to solve circular reference problems

Accessibility analysis algorithm

The algorithm principle of accessibility analysis is to start by traversing the object root reference (stack, static reference of method table and constant reference area, local method stack) to search all reachable objects, to form a chain of references, to tag both reachable objects and unreachable objects at the same time, to indicate that no references exist, and can be GC Recycling

In general, what we call GC is in the new generation and the old age, the new generation of objects survival time is short, low survival rate is generally used to stop - copy algorithm, the old age object survival time is long, high survival rate, the general use of markers - Organize, Mark - clear algorithms, specifically what algorithm to use and the specific garbage collector

Typically new, for the JVM, where the object is placed in the Cenozoic, after the Minor GC continues to survive, the Minor GC will move all live objects in Eden to the Survivor area, and tag, if the number of tokens reaches 15 (the default), the object remains alive, Then the object will be put into the Laosheng generation.

When doing minor GC, only the new generation is recycled, will not be recycled in the old age. Even if the object of the old age is not indexed, it will still survive until the next full GC (Major GC).

GC Memory Recovery mechanism

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.