Reference to object during finalize

后端 未结 5 1380
爱一瞬间的悲伤
爱一瞬间的悲伤 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:47

    If you absolutely must resurrect objects, this JavaWorld article suggests creating a fresh instance rather than resurrecting the instance being finalized because if the instance being finalized becomes eligible for collection again it will simply be collected (the finalizer won't be run again).

提交回复
热议问题