Phantom References 用于事后分析操作。 Java 规范规定,在清除幻象引用本身之前,不会释放幻象引用对象。
我的问题是:此功能(对象未解除分配)有什么作用?
(我想到的唯一想法是允许 native 代码对对象进行事后清理,但这并没有多大说服力)。
最佳答案
编辑,因为我首先误解了这个问题:
引自此处http://www.memorymanagement.org/glossary/p.html :
The Java specification says that the phantom reference is not cleared when the reference object is enqueued, but actually, there's no way in the language to tell whether that has been done or not. In some implementations, JNI weak global references are weaker than phantom references, and provide a way to access phantom reachable objects.
但我没有发现其他的引用文献会说同样的话。
关于java - 虚引用对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/80690/