类 | 描述 |
---|---|
PhantomReference<T> |
在收集者确定其指示物可能被回收之后排入队列的Phantom参考对象。
|
Reference<T> |
参考对象的抽象基类。
|
ReferenceQueue<T> |
在检测到适当的可达性更改后,引用队列被垃圾收集器附加到哪个已注册的参考对象。
|
SoftReference<T> |
软参考对象,由垃圾收集器根据内存需求自行清除。
|
WeakReference<T> |
弱参考对象,不会阻止其指定对象的最终确定,最终确定,然后被回收。
|
Each reference-object type is implemented by a subclass of the abstract base
class. An instance of one of these subclasses encapsulates a single reference to a particular object, called the referent. Every reference object provides methods for getting and clearing the reference. Aside from the clearing operation reference objects are otherwise immutable, so no Reference
set
operation is provided. A program may further subclass these subclasses, adding whatever fields and methods are required for its purposes, or it may use these subclasses without change.
ReferenceQueue
class.
The relationship between a registered reference object and its queue is one-sided. That is, a queue does not keep track of the references that are registered with it. If a registered reference becomes unreachable itself, then it will never be enqueued. It is the responsibility of the program using reference objects to ensure that the objects remain reachable for as long as the program is interested in their referents.
While some programs will choose to dedicate a thread to removing reference objects from one or more queues and processing them, this is by no means necessary. A tactic that often works well is to examine a reference queue in the course of performing some other fairly-frequent action. For example, a hashtable that uses weak references to implement weak keys could poll its reference queue each time the table is accessed. This is how the
class works. Because the WeakHashMap
method simply checks an internal data structure, this check will add little overhead to the hashtable access methods. ReferenceQueue.poll
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.