Win a copy of Rust Web Development this week in the Other Languages 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Garbage collection: all or nothing???

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic