So the answer is 5 objects created and 2 eligible for GC. Now you ask "why do you said 2 objects eligile for GC and spoken only about one Dozen object?
Have you ever heard about the "Island of Isolation"? Its an unreachable place for people outside the island, but inside the island thing happens. What do I mean? Look:
Before:
da[1] = null
After:
When you lose the reference to the Dozen object the int array (another object) is unreachable! It lives now in the Island of Isolation, the object itself still have a reference (the Dozen dz attribute) but since Dozen is unreachable you cant ever reach Dozen.dz!
Thats why you have 2 eligible objects for GC, not only the objects that have no reference become eligible, but all the objects that cant be reachable (living in the island of isolation).
So be carefull, when you find an object that has no reference, check if the object attributes doesnt refer to another objects that become unreachable too!
Sorry for the long post, hope it helps you understand what happen!
[ November 16, 2008: Message edited by: Fabio Nascimento ]
[ November 16, 2008: Message edited by: Fabio Nascimento ]