Hi,
The following question ask how many object are eligible for GC after line 10.
The answer is 3 but I don't know which one is the third object. To clarify it I was trying to drew the picture what is happening(but I am not sure is it correct)
line: 7. Garb gb1=new Garb(new Garb(new Garb(null))); // 3 objects created:
gb1-->|_|
gb1.g-->|_|
gb1.g.g->|_|
line: 8. gb1.g.g=new Garb(new Garb(null)); // 2 objects created, 1 eligible to GC:
gb1-->|_|
gb1.g-->|_|
gb1.g.g->|_| |_| //1st object eligible for GC
gab1.g.g.g->|_|
line: 9. Garb gb2=new Garb(new Garb(new Garb(gb1))); // Another 3 objects created:
gb1-->|_|<--gb2.g.g.g
gb1.g-->|_|
gb1.g.g->|_| |_|//1st object eligible to GC
gab1.g.g.g->|_|
gb2-->|_|
gb2.g-->|_|
gb2.g.g-->|_|
line: 10. gb2.g=gb1.g;// 2nd object eligile to GC
gb1-->|_|<--gb2.g.g.g
gb1.g-->|_|<--gb2
gb1.g.g->|_| |_|//1st object eligible to GC
gab1.g.g.g->|_|
|_|//2nd
gb2.g-->|_|
gb2.g.g-->|_|
Thus, I am not sure which is the third object available for GC.
Any help will be appreciated.
Kamila