when an object is eligible for a garbage collector?

試著忘記壹切 提交于 2019-12-04 10:22:30

The main reason this question is confusing IMO is that there are 2 variables named o. One is the instance variable o and the other is the local variable o inside method doSomething().

Time            instance var o    local var o
Before Line 5:            null               
Line 5:                   null       Object#1
Line 6:               Object#1       Object#1
Line 7:               Object#1       Object#2
Line 8:                   null       Object#2   <- No more references to Object#1

So on (or after executing) line 8, Object#1 is eligible for collection.

The question is a bit confusing because it is after line 3 is called the second time that the object is eligible because it clears the second reference o.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!