Java Garbage Collector algorithm and java garbage collection Algorithm

Source: Internet
Author: User

Java Garbage Collector algorithm and java garbage collection Algorithm
Reference Counting Algorithm:
Python
Add a reference counter to the object. Every time a counter is referenced, the counter value is added with 1. When the reference fails, the counter value is reduced by 1; objects whose counter is 0 at any time cannot be used again.

Disadvantage: It is difficult to solve the issue of circular reference between objects.
Since each other is referenced by each other, their count is not 0, so the reference counting algorithm cannot notify the GC collector to recycle them.

Root search algorithm:
Java, C #, and Lisp use this.

Using a series of objects named "GC Roots" as the starting point, you can start to search down from these nodes. The path you search for is referred to as Reference Chain ), when an object to GC Roots is not connected by any reference chain (in graph theory, it is impossible to reach this object from GC Roots), it is proved that this object is unavailable.

Garbage collection algorithm:
1. Mark-clear Algorithm

First, all objects to be recycled are marked, and all marked objects are recycled after marking.

2. Copy Algorithms
Divide the available memory into two equal parts by capacity, and use only one of them at a time. When this memory is used up, you can copy the remaining objects to another one, and then clear the used memory space.

The memory is divided into a large Eden space and two smaller memory vor spaces. Each time Eden and the memory vor space are used. When recycling, copy the objects that are stored in the Eden and movie vor to another movie vor space at one time, and finally clear the Eden and the movie vor space used just now.

3. Mark-cleaning algorithm
Move all surviving objects to one end, and then clear the memory outside the boundary.

4. Generational Collection Algorithms
The memory is divided into several parts based on the lifecycle of the object. Use the most appropriate collection algorithm based on the characteristics of each age.

The new generation uses the replication algorithm, replacing the old generation with the "tag-clean" or "tag-sort" algorithm.

Reference Book: Zhou Zhiming deep understanding of Java virtual machines


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.