posted 12 years ago
Hi all,
I am having hard time understanding the concept of garbage collection.
I will throw in a few examples in different posts and will justify my answer.
To begin with, here is first example.
1.
Q: Which are true about the objects created within main(), and eligible for garbage collection when //do stuff line is reached
A. Three objects were created
B. Four objects were created
C. Five objects were created -This is correct. Objects created are da(array object), da[0], dz of da[0], d, dz of d.
D. Zero objects are eligible for garbage collection
E. One object is eligible for garbage collection.
F. Two objects are eligible for garbage collection. This is right answer as per book and I am not able to understand why. The explanation is not very clear. It just says second Dozen object(and its "int array object") are not reachable.
G. Three objects are eligible for garbage collection.-According to my understanding(and I could be wrong), this is right answer as d and da[1] is explicitly made null and if d is made null, dz of d should also be available for GC (even though it has a valid reference to an array object..island of isolation?). Actually, as per my understanding, I think that even dz of da[1] will also be available for GC (island of isolation?), so according to me 4 objects are available for GC, however there was no option of 4 objects hence I selected this option .
I will post other example once I understand this perfectly.
Appreciate any help.
Thanks
Chintan.