Which of the following could be a result of attempting to compile and run the program? a. A1A2A3A1 b. A0A0A0A0A1A2A3 c. A1A2A3A1A2A3 d. A1A2A3A1A1A2A3 e. A1A2A3A1A3A2A1 f. A0A1A2A3A1A2A3 My answer was a, c, d, e. The correct answer apparently doesn't include c. A1A2A3A1 is printed in the for loop in method m1. The call to System.gc() does not guarantee the gc will run, so it might be possible none of the object is gc'ed (that's answer a). Another option is they are all gc'ed and that could happen in any order. That gives you answers d and e. Cool. What happens with c? Isn't it possible that A2 and A3 are gc'ed but A1 isn't??? Why not?? It sort of implies the GC might collect everything or not collect anything at all ... Thanks! Edited by Corey McGlone: Added CODE Tags [ March 30, 2004: Message edited by: Corey McGlone ]
Hi Lionel, Answer c is not valid because you'r dealing with so called islands of isolation. The objects refer to each other but there is no live reference to any of them, so they are eligible for garbage collection as a group and no individual object will be missed. Very nice question, may I ask where you got it from? And if it's available for download or something. Greetings, Gian Franco [ March 30, 2004: Message edited by: Gian Franco Casula ]
"Eppur si muove!"
posted 16 years ago
Hi Gian Franco, So for island of isolation the gc does work with an all or nothing policy ... I got that question from Dan Chisholm's exan: http://home.comcast.net/~danchisholm/march13/topic/index.html Another rancher sent me that link. I don't know if that is really Dan's page or http://www.danchisholm.net is. They have different "latest exams". Cheers, L.