What are GC algorithms?

Source: Internet
Author: User
(i), reference counting method

Explanation: Each object has a reference counter, and when the other declared variables point to the object, the counter is + 1, and when the point disappears, the counter-1. Garbage collection reclaims only objects with a count of 0.
Disadvantage: The case of circular references cannot be recycled, for example a refers to a b,b reference to a c,c reference. This GC algorithm also requires the compiler to mate and count the object references, requiring additional code generation. (ii), Root search algorithm

Explanation: set up a number of root objects, when an object cannot be reached by any of the root object references, then this object can request a "rebirth" opportunity once in finalize, or directly ignore finalize and choose direct death.
GC roots objects include (from memory model analysis): 1. The object referenced in the virtual machine stack . 2. The object that is referenced by JNI in the local method stack . 3. The object referenced by a static type in the method area . 4. The object referenced by the constant in the method area .
So, the question is, how to recycle objects that cannot be "reached" through the root search algorithm.
For:
Algorithm one: Tag-cleanup algorithm (starting from the GC roots tag, Cleanup starts traversing the heap from the heap address, and then finds no marked, and kills, drawbacks: )
Algorithm two: The Replication algorithm (the New Generation (Eden) algorithm used in the heap, also known as minor GC.
Algorithm three: marker-collation Algorithm (collation is to move the memory address on the separated object to the continuous address)

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.