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.
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 ]
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 !
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.)
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