This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes another GC (levteck.com) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "another GC (levteck.com)" Watch "another GC (levteck.com)" New topic
Author

another GC (levteck.com)

Cathy Song
Ranch Hand

Joined: Aug 24, 2003
Posts: 270

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.
Vad Fogel
Ranch Hand

Joined: Aug 25, 2003
Posts: 504
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 ]
Harwinder Bhatia
Ranch Hand

Joined: Oct 17, 2003
Posts: 150
To me, neither seem to be correct. There's no guarantee when the garbage collector will run.
Cheers
Harwinder
Vinod Sinha
Ranch Hand

Joined: Oct 16, 2003
Posts: 43
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

Joined: Aug 24, 2003
Posts: 270
Thanks for clearing my concept.
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8875
    
    5
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.


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: another GC (levteck.com)