java garbage collection and null reference

前端 未结 6 1781
梦谈多话
梦谈多话 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

    The c3 itself is just a reference variable, which is not in the heap space (i.e. not in the scope of garbage collection)

    The line CardBoard c3 = c1.go(c2); only sets the c3 reference to null Thus c3 has not impact on garbage collection as it doesn't make any object eligible.

提交回复
热议问题