| Author |
Double K&B Chapter 3- Question 11
|
Prithvi Sehgal
Ranch Hand
Joined: Oct 13, 2009
Posts: 771
|
|
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,
|
Prithvi/Beenish,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16680
|
|
Hint: take a look at line 4 of your post.
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Prithvi Sehgal
Ranch Hand
Joined: Oct 13, 2009
Posts: 771
|
|
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.
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
This question has been asked many times before. Search the forum for "alpha beta", you'll find discussions like the following
http://www.coderanch.com/t/481398/Programmer-Certification-SCJP/certification/many-eligible-gc
http://www.coderanch.com/t/474980/Programmer-Certification-SCJP/certification/Garbage-Collection-Clarification
http://www.coderanch.com/t/469606/Programmer-Certification-SCJP/certification/Garbage-Collection
|
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
|
 |
Prithvi Sehgal
Ranch Hand
Joined: Oct 13, 2009
Posts: 771
|
|
Thanks Ankit.
Understood it. Very minor mistake i was making, will take care in future.
Best Regards,
|
 |
 |
|
|
subject: Double K&B Chapter 3- Question 11
|
|
|