avatar
GC finalize()一问# Java - 爪哇娇娃
m*k
1
according to the book, for an obj to be GC,
finalize() is never run more than once on any object,
I am puzzled here, since it is possible that the obj is made reachable again
in its finalize(), then after a while, this obj may again become unreachable,
then finalize might again be called. 如此往复。 so the finalize() is called
more than once.
望指教,谢谢啦。
avatar
m*t
2

That's an interesting question. I never thought finalize could
be used this way (or at least not for any practical reasons).
The javadoc of finalize does sound vague or even conflicting.
My guess is if an object is made available in its finalize, next time
it becomes unreachable, the VM won't call finalize and will reclaim
it directly.
I really can't think of any practical stuation where you want to
wait until finalize to "revive" an object.

【在 m*****k 的大作中提到】
: according to the book, for an obj to be GC,
: finalize() is never run more than once on any object,
: I am puzzled here, since it is possible that the obj is made reachable again
: in its finalize(), then after a while, this obj may again become unreachable,
: then finalize might again be called. 如此往复。 so the finalize() is called
: more than once.
: 望指教,谢谢啦。

avatar
n*k
3

unreachable,
JVM only call finalize() once! If inside the code, this object is referred by
others, then it will never be reclaimed, so will cause memeory leak. So it
should be careful if you want to override this method().

【在 m*****k 的大作中提到】
: according to the book, for an obj to be GC,
: finalize() is never run more than once on any object,
: I am puzzled here, since it is possible that the obj is made reachable again
: in its finalize(), then after a while, this obj may again become unreachable,
: then finalize might again be called. 如此往复。 so the finalize() is called
: more than once.
: 望指教,谢谢啦。

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。