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