WeakReference
Stay organized with collections
Save and categorize content based on your preferences.
Weak reference objects, which do not prevent their referents from being
made finalizable, finalized, and then reclaimed. Weak references are most
often used to implement canonicalizing mappings.
Suppose that the garbage collector determines at a certain point in time
that an object is weakly
reachable. At that time it will atomically clear all weak references to
that object and all weak references to any other weakly-reachable objects
from which that object is reachable through a chain of strong and soft
references. At the same time it will declare all of the formerly
weakly-reachable objects to be finalizable. At the same time or at some
later time it will enqueue those newly-cleared weak references that are
registered with reference queues.
Public Constructor Summary
|
WeakReference(T referent)
Creates a new weak reference that refers to the given object.
|
|
WeakReference(T referent, ReferenceQueue<? super T> q)
Creates a new weak reference that refers to the given object and is
registered with the given queue.
|
Inherited Method Summary
From class
java.lang.ref.Reference
void
|
clear()
Clears this reference object.
|
boolean
|
enqueue()
Adds this reference object to the queue with which it is registered,
if any.
|
void
|
finalize()
Invoked when the garbage collector has detected that this instance is no longer reachable.
|
T
|
get()
Returns this reference object's referent.
|
boolean
|
isEnqueued()
Tells whether or not this reference object has been enqueued, either by
the program or by the garbage collector.
|
From class
java.lang.Object
Object
|
clone()
Creates and returns a copy of this Object .
|
boolean
|
equals( Object obj)
Compares this instance with the specified object and indicates if they
are equal.
|
void
|
finalize()
Invoked when the garbage collector has detected that this instance is no longer reachable.
|
final
Class<?>
|
getClass()
Returns the unique instance of Class that represents this
object's class.
|
int
|
hashCode()
Returns an integer hash code for this object.
|
final
void
|
notify()
Causes a thread which is waiting on this object's monitor (by means of
calling one of the wait() methods) to be woken up.
|
final
void
|
notifyAll()
Causes all threads which are waiting on this object's monitor (by means
of calling one of the wait() methods) to be woken up.
|
String
|
toString()
Returns a string containing a concise, human-readable description of this
object.
|
final
void
|
wait(long timeout, int nanos)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
final
void
|
wait(long timeout)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
final
void
|
wait()
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.
|
Public Constructors
public
WeakReference
(T referent)
Creates a new weak reference that refers to the given object. The new
reference is not registered with any queue.
Parameters
referent |
object the new weak reference will refer to
|
public
WeakReference
(T referent, ReferenceQueue<? super T> q)
Creates a new weak reference that refers to the given object and is
registered with the given queue.
Parameters
referent |
object the new weak reference will refer to |
q |
the queue with which the reference is to be registered,
or null if registration is not required
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
{"lastModified": "Last updated 2024-07-10 UTC."}