Reference to object during finalize

后端 未结 5 1378
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-30 09:50

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

class foo {
    ...
    public void finalize() {
        b         


        
5条回答
  •  一向
    一向 (楼主)
    2020-11-30 10:45

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

    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

提交回复
热议问题