Gcroot and reference types in Java

Source: Internet
Author: User

See an old question, how does Java determine which objects are recycled?

A: The search from gcroot root is unreachable and the object that has not been resurrected after the Mark cleanup is identified as a garbage object to clean up. Note In Java there is no scope for the object, only the scope of the object's reference. Java garbage collection does not employ a reference counting algorithm because it does not solve circular reference problems. Java garbage algorithm is actually marked out that those objects are referenced, others are not tagged is useless can be recycled, rather than directly find out which objects are useless.

So, which objects can be used as gcroot?

It is actually a set of root references, mainly including the local variable table in the virtual machine stack (which is actually the parameters local variables such as all the methods being called), the static property reference of the class, the constant object reference, and the object reference in the local method stack. In fact, Java garbage collection is primarily for heap memory, and these references come from other parts of the JVM Runtime data area: Virtual machine stack, local method area, method area.

What are the classes of reference types in Java and what are the uses?

The most common use is a strong reference, where only such a reference exists, and garbage collection does not clean up the object it points to. The second is soft references, which are recycled only when the garbage collection is running out of memory space, and are used more in cached objects. The second is the weak reference, as long as a garbage collection occurs and is recycled. The last is a virtual reference, which is the weakest reference relationship.

Gcroot and reference types in Java

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.