Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Double K&B Chapter 3- Question 11

 
Prithvi Sehgal
Ranch Hand
Posts: 774
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,
This is an exercise question from K&B and i have a doubt.


To my knowledge, there should be two objects eligible for garbage collection. a1 and b1, but book says only one object is eligible for
garbage collection. Exact explanation is written like this

It should be clear that there is still a reference to the object referred to by a2, and that there is still a reference to the object referred by
a2.b2. What might be less clear is that you can still access the other Beta object through the static variable a2.b1, because its static.

Why a2.b1 is an object? It should be a reference variable having null because we never initialized the value of a2.b1. By default when it is
initialized it will be having a value of null.

Please clarify.

Thanks,
 
Henry Wong
author
Marshal
Pie
Posts: 21212
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hint: take a look at line 4 of your post.
 
Prithvi Sehgal
Ranch Hand
Posts: 774
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am unable to understand still why only one object is eligible for garbage collection.
What about objects b1 and b2 in main? Please can someone explain me this problem
and this static reference field. I am confused.
 
Prithvi Sehgal
Ranch Hand
Posts: 774
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ankit.

Understood it. Very minor mistake i was making, will take care in future.

Best Regards,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic