java - 虚引用对象

标签 java finalize phantom-reference

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/

相关文章:

java - 缓存键中的通配符

angular - rxjs takeUntil 不执行finalize

java - 当 PhantomReference/SoftReference/WeakReference 排队时,你怎么知道它引用了什么?

java - 如何在 Java 中打印/获取传入 HTTP POST 请求的有效负载(使用套接字)

java - Android Studio AVD 模拟器在 Windows 更新后透明

Java并手动执行finalize

java - 如何使用 PhantomReference 报告 Android/Java 中的内存泄漏

Java:PhantomReference、ReferenceQueue 和 finalize

java - 捕获并记录响应正文

java - Java 中 Finalize() 操作的顺序