Weak reference WeakReference in Java

Source: Internet
Author: User

I. Overview

Class Structure:

Java.lang.Object  java.lang.ref.reference<t>      java.lang.ref.weakreference<t>
Statement:Public classweakreference<t>Extends reference<t>

Assume that the garbage collector determines that an object is a weakly reachable object at a point in time. At this point, it will automatically clear all weak references to this object, as well as all weak references to any other weakly reachable objects that can be reached from the object by strong reference chains and soft references. It will also declare all previous weakly reachable objects to be terminated. At the same time or later, it joins the queue with weak references to new purges that have been registered with the reference queue.


Second, the construction method

1. public weakreference(T referent) Creates a new weak reference that references the 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) Creates a new weak reference that references the given object and registers the reference with the given queue.
Parameters: referent -The new weak reference will refer to the object q -the queue to which the reference is registered, or null if registration is not required;


Weak reference WeakReference 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.