由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - GC finalize()一问
相关主题
Java都在什么时候进行Garbage collection?java multithreading常识一问
Java questions 51-100Where I can find comparison of JVMs
Re: help for running CPU intensive progrjava source code analyzing tool
JDK Source?help: cannot generate index.html using javadoc
Another garbage collection questionMini Javadoc Howto -- Re: help: cannot generate index.html using javadoc
Extracting JavaDoc comment?faint, unreachable statement in java
为什么java没有destructorHow to append something on a file?
菜鸟问题一问how to multicast objects to clients in java?
相关话题的讨论汇总
话题: finalize话题: gc话题: obj话题: object
进入Java版参与讨论
1 (共1页)
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.
: 望指教,谢谢啦。

1 (共1页)
进入Java版参与讨论
相关主题
how to multicast objects to clients in java?Another garbage collection question
[转载] Re: 觉得自己很笨Extracting JavaDoc comment?
Any good project documentation tools (free?)为什么java没有destructor
巨量数据读取问题求助菜鸟问题一问
Java都在什么时候进行Garbage collection?java multithreading常识一问
Java questions 51-100Where I can find comparison of JVMs
Re: help for running CPU intensive progrjava source code analyzing tool
JDK Source?help: cannot generate index.html using javadoc
相关话题的讨论汇总
话题: finalize话题: gc话题: obj话题: object