Just as with weak references , a soft reference can be created with an associated reference queue , and the reference is enqueued when it is cleared by the garbage collector 正如弱引用一样,软引用也可创建为具有一个相关的引用队列,引用在被垃圾收集器清除时进入队列。
This month , sanitation engineer brian goetz explores a common cause of unintentional object retention and shows how to plug the leak with weak references 本月,负责保障应用程序健康的工程师brian goetz探讨了无意识的对象保留的常见原因,并展示了如何用弱引用堵住泄漏。
Soft , weak , and phantom reference objects offer three different ways to refer to a heap object without preventing its collection 软引用( soft reference ) 、弱引用( weak reference )和虚引用( phantom reference )对象提供了三种不同的方式来在不妨碍收集的情况下引用堆对象。
Soft references , like weak references , can help applications prevent object loitering by enlisting the aid of the garbage collector in making cache eviction decisions 与弱引用一样,软引用通过利用垃圾收集器在作出缓存回收决策方面的帮助,有助于防止应用程序出现对象游离。
Reference queues are not as useful with soft references as with weak references , but they could be used to raise a management alert that the application is starting to run low on memory 引用队列对于软引用来说,没有对弱引用那么有用,但是它们可以用于发出管理警报,说明应用程序开始缺少内存。
On the other hand , when you create a weak reference to an object , you do not extend the lifetime of the referent at all ; you simply maintain an alternate way to reach it 另一方面,在创建对一个对象的弱引用时,完全没有扩展referent的生命周期,只是在对象仍然存活的时候,保持另一种到达它的方法。
The sample also shows how an application can control some of the garbage collector s behavior , for example , in forcing collections , promoting objects , and working with weak references to objects 本示例还说明了应用程序如何能够控制垃圾回收器在诸如强制回收、提示对象和使用对对象的弱引用等方面的行为。
We saw how weak references can provide an application with an alternate means of reaching an object while it is used by the program , but without prolonging its lifetime . another subclass of 中我们看到了,弱引用如何可以给应用程序提供当对象被程序使用时另一种到达该对象的方法,但是不会延长对象的生命周期。
Weak references are most useful for building weak collections , such as those that store metadata about objects only for as long as the rest of the application uses those objects - which is exactly what the 弱引用对于构造弱集合最有用,如那些在应用程序的其余部分使用对象期间存储关于这些对象的元数据的集合这就是