开发者

Java variables that prone to be collected by garbage collector

I don't exactly remember but there was an 开发者_如何学运维article for Java that explains variable modifiers that makes them prone to be collected by garbage collector. Is there any mechanism for Java to define variables as stepped to be collecting by garbage collector?


What you're looking for might be Weak Reference, have a look here: http://en.wikipedia.org/wiki/Weak_reference


If an object is referenced (directly or indirectly) by a variable, it won't be collected at all.

Apart from that, there is nothing. Garbage collector is a black box and just does what it fits (even System.gc() is only a suggestion to run the garbage collection).


I think you were referring to the finalize keyword. Do take note that this only makes the suggestion to the compiler. The compiler may choose not to garbage collect. Or perhaps you were referring to weak references...


No, except for the weak reference api.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜