• 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

Java caps GC question

 
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which statements about garbage collection are true?
[a] The garbage collector runs in low memory situations
[b] You can run the garbage collector when ever you want.
[c] When it runs it releases the memory allocated by an object.
[d] Garbage collector immediately runs when you set the references to null.
Ans: a,c
I have a doubt regarding [d]. When an object reference is set to null, then the object becomes ELIGIBLE for garbage collection, but garbage collector MAY NOT run immediately. Am I right?
Thanks,
Cathy.
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are correct Kathy. There is no guarantee that the garbage collector will run, and that is the concept that the exam focuses on.
I would argue that answer A is not always true, because such behavior is not guaranteed. For the purposes of the exam, I would say that it is false.
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another ambiguous question (I'm starting to dislike this book):
[a] The garbage collector runs in low memory situations
It runs whenever it wants. A VM implementation might decide to run each Sunday after breakfast - ideally, an implementation runs when memory is low or CPU activity is down, I would say this is not a correct answer. The keyword here being "ideally" - nothing is guaranteed.
[b] You can run the garbage collector when ever you want.
No you can't. The API provides both System.gc() and Runtime.gc() that "suggest" to the garbage collector that now is a good time to run. It is not gauranteed when or even if the garbage collector will honour your suggestion. I'd say this is incorrect.
[c] When it runs it releases the memory allocated by an object.
No it doesn't. It releases the memory allocated by an object "if there are no valid references to it". This is incorrect.
[d] Garbage collector immediately runs when you set the references to null.
Incorrect. Setting references to null "might" flag the object that it referred to as being eligible for garbage collection. I say "might" because there "might" be other references to it - if there aren't, then it "will" be flagged as eligible for garbage collection. Whether or not the garbage collector runs does not come into this scenario at all. Another incorrect option.
Conclusion: There are no correct answers. I think it's important to be as accurate as possible about the wording of questions - in particular, offer them to an independant audience to request feedback; these type of ambiguities are immediately noticeable (at least they are to me anyway).
 
author
Posts: 9031
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cathy -
What was the source of that question? (Jeez I hope I didn't write that one )
On the real exam, the GC questions are VERY 'trickily' worded, although I'd say they're worded better than this question. I don't think any of the answers are strictly correct, C *might* be but it's worded very ambiguously. I don't think you'll see ambiguous writing like this on the real exam.
 
Cathy Song
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bert,
The question is not from your book. Its from Java caps.
http://www.javacaps.com/scjp_gar.html
I am not sure which book Tony is talking about.
Thanks,
Cathy.
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I did the exam in December 2002, the questions were worded such that they were assessing your knowledge of the language - of course, some of these were tricky, however, I wouldn't say that any of them were "indeterminate".
 
reply
    Bookmark Topic Watch Topic
  • New Topic