File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes another GC ( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "another GC (" Watch "another GC (" New topic

another GC (

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.
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

Joined: Oct 14, 2002
Posts: 8898
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:
subject: another GC (
It's not a secret anymore!