在定稿过程中引用对象 [英] Reference to object during finalize

查看:107
本文介绍了在定稿过程中引用对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您在完成调用期间保存对当前对象的引用,会发生什么情况?例如:

What happens if you save a reference to the current object during the finalize call? For example:

class foo {
    ...
    public void finalize() {
        bar.REFERENCE = this;
    }
}

对象是垃圾收集还是不收集?当您尝试访问 bar.REFERENCE 时,会发生什么情况?

Is the object garbage-collected, or not? What happens when you try to access bar.REFERENCE later?

推荐答案

该对象不是垃圾收集。这就是所谓的Object resurrection。

The object is not garbage collected. This is know as "Object resurrection".

在一些环境中,一旦终结器被调用,gc不会再调用它,你必须小心。 NET你可以重新注册终结器,但我不确定Java

You must be careful with that, once the finalizer is called the gc won't call it again, on some enviroments like .NET you can re-register the finalizer but i'm not sure about java

这篇关于在定稿过程中引用对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆