Forums Register Login

another GC question help

+Pie Number of slices to send: Send
hi guys the quest below is on SCJP book Page 284 question 11;




the question is until the code to do stuff() how many objects are eligable for GC

answer is 1

can some one tell me which is the one object to be GC and how to work it out.

thanks very much.


ps: my understance is there will be only 5 objects created which are a1,b1, a2,b2. and alpha static instance, and the instance field in Alpha "Beta b2" will just inital to null when Alpha object is created. a1.b2 and a2.b2 are just references to object b1 and b2 respectively, therefore when a1 assign to null only object a1 is eligable to GC, am I correct?
+Pie Number of slices to send: Send
Try to make a drawing for yourself with on one side the objects, the other side the references and in the middle arrows to connect the references with the objects. Then walk through the code and change the arrows. Once you're done you'll know which objects are eligible. But remember that Alpha.b2 is static.
+Pie Number of slices to send: Send
He loves you so much! And I'm baking the cake! I'm going to put this tiny ad in the cake:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 972 times.
Similar Threads
Question about object creation
Objects Eligible for GC
kathy sierra question doubt
Eligible for garbage collection
Self Test Answers Chapter 3 Question 11
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 00:28:51.