java garbage collection and null reference

前端 未结 6 1778
梦谈多话
梦谈多话 2020-12-20 05:27

In my studying for OCJP I came across the following question:

class CardBoard {
           Short story = 200;
           CardBoard go(CardBoard cb) {
                


        
6条回答
  •  [愿得一人]
    2020-12-20 06:20

    c3 is not an object. It's a variable referencing null. A variable can't be eligible to GC. Only objects can be eligible to GC.

    The objects eligible to GC are the Cardboard which was initially referenced by c1, and the Short instance initially referenced by the CardBoard initially referenced by c1.

提交回复
热议问题