Hi Fellow Ranchers! First of all, I would to thank everyone who have contributed to this forum. I'm on the process of studying for my
SCJP and I'm really learn a lot from the different topics posted here. Anyway, I have a question with regards to one of Dan's Mock Exam Question on Garbage Collection.
Question 1:
After method m1 returns the objects on which of the following lines are eligible for garbage collection?
a. 1
b. 2
c. 3
d. 4
e. None of the above.
f. Compiler error.
g. Run time error.
h. None of the above.
Question 2:
After method m1 returns the objects on which of the following lines are eligible for garbage collection?
a. 1
b. 2
c. 3
d. 4
e. None of the above.
f. Compiler error.
g. Run time error.
h. None of the above.
I believe the answer to Question 1 is letter E and the answer to Question 2 is letter B, C, D.
My question is how come when the reference of the array is set to null (Question 1), it is not eligible for garbage collection but if its elements were set to null (Question 2) then they would be eligible? Is this really how the garbage collection works?
Thanks