我们可以看到“幻影可达”和“不可达”一样不可达:§
An object is phantom reachable if it is neither strongly, softly, nor weakly reachable, it has been finalized, and some phantom reference refers to it.
Finally, an object is unreachable, and therefore eligible for reclamation, when it is not reachable in any of the above ways.
现在,来自:http://download.oracle.com/javase/6/docs/api/java/lang/ref/PhantomReference.html
Unlike soft and weak references, phantom references are not automatically cleared by the garbage collector as they are enqueued. An object that is reachable via phantom references will remain so until all such references are cleared or themselves become unreachable.
基本原理是什么?有没有?
这是 Java API 怪癖的又一个典型案例吗?
最佳答案
软引用在入队时会被清除,因为软引用的主要用途是允许缓存大对象,而清除软引用允许对缓存的大对象进行垃圾回收。
弱引用在入队时被清除,因为弱引用的主要用途是允许一个人引用一个对象而不阻止它被垃圾收集,所以一旦对象入队就清除引用允许对象被垃圾收集.
幻影引用在入队时不会被清除,因为幻影引用的一个用例是允许在对象被垃圾收集之前执行清理。通过不清除引用,该对象将保持幻象可达(并且不符合垃圾收集的条件),直到该对象的 PhantomReference 被用户清除,或者 PhantomReference 本身被垃圾收集。
这解释了here ,
An object is phantom reachable if it is neither strongly, softly, nor weakly reachable, it has been finalized, and some phantom reference refers to it.
Finally, an object is unreachable, and therefore eligible for reclamation, when it is not reachable in any of the above ways.
关于java - 为什么幻影引用在排队时没有被清除?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7048767/