Weak references of WeakReference and javaweakreference in java

Source: Internet
Author: User

Weak references of WeakReference and javaweakreference in java

I. Overview

Class Structure:

java.lang.Object  java.lang.ref.Reference<T>      java.lang.ref.WeakReference<T>
Declaration: public class WeakReference <T>Extends Reference <T>

Assume that the Garbage Collector determines that an object is weak and reachable at a certain time point. At this time, it will automatically clear all weak references to this object, and through the strong reference chain and soft reference, it can be used to obtain all weak references from any other weak reachable objects. At the same time, it declares that all the previous weak reachable objects can be terminated. At the same time or later, it adds weak references that have been registered with the reference queue to the queue.


Ii. Constructor

1. publicWeakReference(T referent) creates a new weak reference that references a given object. The new reference is not registered with any queue.

Parameters: referent-The new weak reference will reference the object


2. public WeakReference(T referent, ReferenceQueue <? SuperT> q) Create a New Weak reference that references a given object and register the reference with the given queue.
Parameters: referent-The new weak reference will reference the object q-The queue to which the reference is registered. If you do not need to register the queue, it is Null


Related Article

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.