What objects can be used as GC roots objects for GC-referenced accessibility analysis algorithms

Source: Internet
Author: User

Let's start with the idea of the Accessibility analysis algorithm: Starting with an object called GC roots, if an object is connected to a GC roots without any reference chain, then this object is not available.

There are several types of objects that can be used as GC roots in Java:

Objects referenced in the virtual machine stack, object referenced by the method area class static property, objects referenced by the method area constant pool, objects referenced by the local method stack JNI reference


Although these algorithms can determine whether an object can be recycled, an object may not necessarily be recycled when the above conditions are met. When an object is not up to GC roots, this object is not immediately recycled, but is in a reprieve phase, and it takes two tokens to be truly recycled. If the object does not have a reference chain to the GC roots in the accessibility analysis, it is then first flagged and filtered for the condition that it is necessary to execute the Finalize () method. When an object does not overwrite the Finalize () method or has been called by a virtual machine, it is considered unnecessary.


If the object is necessary to execute the Finalize () method, then this object will be placed in a queue called F-queue, the virtual machine can trigger a finalize () thread to execute, the thread is low priority, and the VM will not commit to wait until it runs out. This is due to the fact that if finalize () performs slowly or a deadlock occurs, it causes the F-queue queue to wait, causing the memory recovery system to crash. The GC is marked for the second time in an object in F-queue, and the object is removed from the collection that is about to be recycled, waiting to be reclaimed.

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.