posted 15 years ago
I don't understand why the answer of this question is "Five obejects were create" and "Two objects are eligible for GC". I agree with there is total five objects were created, but at the line 14, I think there are three objects are eligible for GC. My explaination are follow the code:
at line8, da create a array and has 3 Dozens objects:
da[0] --> "Dozen1"
da[1] --> "Dozen2"
da[2] --> "Dozen3"
(so far created 3 Objects)
Line9, da[0] --> another "Dozen4", give up its object "Dozen1"
(so far, created 4 Objects, 1 eligible for GC)
Line10, d --> new "Dozen5"
(so far created 5 Objects)
Line11, da[1] --> d's "Dozen5", give up its object "Dozen2"
(so far, created 5 Objects, 2 eligible for GC)
Line12, d --> null, give up its object "Dozen5"
(nothing change here, due to the d's object is pointed by da[1])
Line13, da[1] --> null, also give up the object "Dozen5"
(so far, still 5 Objects, but 3 are eligible for GC)
What is wrong with my understanding? why the answer is 2 Object are eligible to GC
Thanks for help
[ September 17, 2008: Message edited by: Doraemon Zhou ]
[ September 17, 2008: Message edited by: Doraemon Zhou ]
Preparing SCJP 6, try to get high score, and looking for a job...