Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Garbage collection: all or nothing???

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there!
Question from a mock exam:

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 ]
 
blacksmith
Posts: 979
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Lionel Orellana
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic