Java Virtual machine garbage collection process

Source: Internet
Author: User

Almost all of the object instances in the Java world are in the JVM heap, and the first thing the garbage collector can do before reclaiming heap memory is to determine which of these objects are still alive and which ones are dead (that is, objects that can no longer be used by any means).

In the mainstream business programming language, Java and C # are used to determine whether an object survives using the root search algorithm (GC Roots tracing). The basic idea of this algorithm is to use a series of objects called "GC Roots" as the starting point, starting from these nodes to search down, the path of the search is called the reference chain, when an object to the GC Roots no reference chain connected (from the GC Roots to this object unreachable), proves that this object is not available.


The objects that can be used as GC roots in Java include the following:

1. The object referenced in the virtual machine stack (local variable table in the stack frame);

2. The object referenced by the class static property in the method area;

3, the object in the method area constant reference;

4. The object referenced by the native method in the local method stack;


If the object finds no reference chain connected to the GC roots after the root search, it will be first marked and filtered, and the condition is whether this object is necessary to execute the Finalize () method when the object does not overwrite the Finalize () method, or Finalize () Method has been called by the virtual machine, and the virtual machine treats both cases as "no need to execute".

If the object is judged to be necessary to execute the Finalize () method, then the object will be placed in a queue named F-queue, and then executed by a low-priority finalizer thread that is automatically created by the virtual machine at a later time. Later, the GC will mark the object in the F-queue for a second small size, and if the object is to successfully save itself in Finalize ()-as long as it is associated with any object on the reference chain, it will be removed from the "soon to be recycled" collection when the second token is taken.


Copyright NOTICE: This article is the original blogger article, reproduced please indicate the source: Http://blog.csdn.net/lingzhm

Java Virtual machine garbage collection process

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.