Hi, Could you please exaplain where objects created & which objects eligible for GC.
All, I understand is objects are created: dz at line 4, da at line 8 , da[0] at line 9 and d at line 10 : Total 4.
Line 12 making "d" object eligible for GC.
But answer is Five objects created and two are eligible for GC.
3. class Dozens {
4. int[] dz = {1,2,3,4,5,6,7,8,9,10,11,12};
5. }
6. public class Eggs {
7. public static void main(
String[] args) {
8. Dozens [] da = new Dozens[3];
9. da[0] = new Dozens();
10. Dozens d = new Dozens();
11. da[1] = d;
12. d = null;
13. da[1]= null;
14. // do stuff
15. }
16.}
Question: How many objects are created and how many of those are eligible for garbage collection when line
14 is reached?