Reference types in Java

Source: Internet
Author: User

First, strong references. No matter when, the garbage collector does not recycle him, and if memory is low, it throws an Oom exception and does not reclaim the strongly referenced object.

Second, soft reference. Through class SoftReference. It tells the garbage collector that it will be reclaimed by the collector when it is out of memory, and if the memory is still insufficient after releasing these objects, Oom will be thrown. {Suitable for cache} strong.

Third, weak references. WeakReference. As soon as the garbage collection is started, objects that are weakly referenced are recycled. The effect is the existence of the coupling between the objects brought by the strong reference. The most common use is in the collection class.

Four, virtual reference. A virtual reference cannot be used to get an object instance, and the sole purpose of setting a virtual reference for an object is to receive a system notification when the object is garbage collected.

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.