m*****k 发帖数: 731 | 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.
望指教,谢谢啦。 | m******t 发帖数: 2416 | 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. : 望指教,谢谢啦。
| n*****k 发帖数: 123 | 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. : 望指教,谢谢啦。
|
|