Java Garbage collector algorithm

Source: Internet
Author: User

Reference counting algorithm:
Python uses the
Add a reference counter to the object, and whenever there is a reference to it, the counter value is incremented by 1, and when the reference fails, the counter value is reduced by 1, and any object with counter 0 at any time is impossible to use again.

Disadvantage: It is difficult to solve the problem of mutual circular references between objects.
Referencing each other, causing their counts to be no more than 0, the reference counting algorithm cannot tell the GC collector to reclaim them.

root search algorithm:
That's what Java,c#,lisp used.

Through a series of objects named "GC Roots" as the starting point, starting from these nodes, the search path is called the reference chain (Reference Chain), when an object to the GC Roots no reference chain connected (in the words of graph theory is from the GC Roots to this object is not available, it proves that this object is not available.

garbage Collection algorithm:
1. Mark-Sweep algorithm

All objects that need to be reclaimed are marked first, and all tagged objects are collected uniformly after the tag is complete.

2. Copy Algorithm
Divide available memory by capacity into two blocks of equal size, using only one piece at a time. When this piece of memory is run out, copy the surviving object to the other piece, and then clean up the used memory space once

Divide the memory into a larger Eden space and two smaller survivor spaces, each using Eden and its survivor. When recovering, copy objects that are still alive in Eden and survivor to another survivor space, and finally clean up Eden and the survivor space just used

3. Mark-Sweep algorithm
Let all surviving objects move toward one end, and then clean out the memory outside the boundary directly

4, generational collection algorithm
Divides the memory into several blocks depending on the life cycle of the object. The most appropriate collection algorithm is used according to the characteristics of each age.

The new generation uses the replication algorithm, the old age with the "mark-clean" or "mark-tidy" algorithm.

Reference book: Zhou Zhiming "in-depth understanding of Java virtual machines"


Java Garbage collector algorithm

Related Article

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.