Objects eligible for garbage collection

前端 未结 5 2113
我寻月下人不归
我寻月下人不归 2020-12-03 12:41

This question was taken from Kathy Sierra SCJP 1.6. How many objects are eligible for garbage collections?

According to Kathy Sierra\'s answer, it is C.

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-03 13:25

    c3 is null, so there is clearly no Object there eligible for garbage collection.

    Note that only two CardBoard objects are created, the two on these lines:

    CardBoard c1 = new CardBoard();
    CardBoard c2 = new CardBoard();
    

    and after the reference juggling, only one of them is without references.

提交回复
热议问题