• 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:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

another GC (levteck.com)

 
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Question 65: Which statements about garbage collection are true?
Select all valid answers.
a. You can directly free the memory allocated by an object.
b. You can directly run the garbage collector whenever you want to.
c. The garbage collector informs your object when it is about to be garbage collected.
d. The garbage collector reclaims an object�s memory as soon as it becomes a candidate for garbage collection.
e. The garbage collector runs in low-memory situations.


The answers given are b,c,e.
I think the possible answer is only e. Am I right? Thanks.
 
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yet another perfect example of a poorly worded question.
b and c are just plain wrong: you can't directly run GC, you can only beg for it to run by calling System.gc(); or Runtime.getRuntime().gc();
c is wrong because GC is not polite enough to notify a lost object when it will be GC-ted. However, the finalize() will be invoked before the object is GC-ted. Again, finalize() is called only once, and there's no guarantee of any kind that that first time the object will be destroyed.
e seems to be the only plausible option to go for. If OutOfMemoryError is to be thrown, the GC will have run by that time. But, the definition of "low-memory situations" is a bit vague.
[ November 04, 2003: Message edited by: Vad Fogel ]
 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To me, neither seem to be correct. There's no guarantee when the garbage collector will run.
Cheers
Harwinder
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Harwinder . None of the answers are correct.
e is wrong because it is not necessary that the garbage collector runs
only when there is low memory. it may run even when the memory is not low !
 
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
Thanks for clearing my concept.
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree that the question is poorly worded. This is really a problem too, because there ARE GC questions like this on the real exam. The folks who created the real exam worked very hard to make their wording very, very precise.
I think I agree that none of these answers is correct in the absolute strictest sense, and that's how the real exam will test you, the absolute strictest sense. Answer c is interesting because you could argue that calling finalize() is a way of informing you that an object is about to be GCed, but the tricky point is that if finalize() was previously called for that object (which is possible), it won't be called again. So, in the absolute strictest sense, c is also wrong.
 
Those who dance are thought mad by those who hear not the music. This tiny ad plays the bagpipes:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic