when will finalize() be called on my class instance in this scenario?

孤街醉人 提交于 2019-12-06 11:27:40

The second thread receives the same actual object instance. You're safe from premature finalization.

It receives a copy of the object reference, if you want to think of it that way.

In addition, finalize is not necessarily run when the garbage collector finds that the object has become garbage - the VM is free to run it at any later time, and to actually reclaim the memory some time after that. You really can't rely on when finalize will be run. However, since what you care about is knowing that finalize won't be called before the second thread finishes with the object, that's immaterial. But worth knowing!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!