l**********9 发帖数: 537 | 1 为什么不是A?2个对象互相有成员变量引用对方, gc也会回收吗?
谢谢 |
k********0 发帖数: 585 | 2 2个对象互相有成员变量引用对方, gc也会回收吗?
To my knowlege, new java vm can detect such cases. |
a****l 发帖数: 8211 | 3 A is probably true, because the compiler is make by someone who slipped
through interview by only talking.
【在 l**********9 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 为什么不是A?2个对象互相有成员变量引用对方, gc也会回收吗? : 谢谢
|
D**C 发帖数: 6754 | 4 you already set the source to null.
then the reference is pointing to null also.
so both obj are good for gc.
why won't they?
then what's the point to set an obj to null? |
l**********9 发帖数: 537 | |
g***i 发帖数: 408 | 6 这是一道SCJP的题吧,考点就是CIRCULAR REFERENCE AND GARBAGE COLLECTION.
这种题只要记住一点,GC的关键不是设不设null,而是Unreachable :An object
enters an unreachable state when no more strong references to it exist. When
an object is unreachable, it is a candidate for collection.
http://java.sun.com/docs/books/performance/1st_edition/html/JPAppGC.fm.html
A.3.4 Unreachable 有详细的解释。 |
b***e 发帖数: 1419 | 7 To my knowledge, the very first version of Java JVM can detect such cases.
As a matter of fact, the only language I know that doesn't do it is PHP4.
【在 k********0 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 2个对象互相有成员变量引用对方, gc也会回收吗? : To my knowlege, new java vm can detect such cases.
|