aspose file tools*
The moose likes Mock Exam Errata and the fly likes Garbage Collection strikes again... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "Garbage Collection strikes again..." Watch "Garbage Collection strikes again..." New topic
Author

Garbage Collection strikes again...

Lucy Das
Greenhorn

Joined: Jul 14, 2002
Posts: 8
Here's a question I found on a test referenced by jiris.com... called JavaQuestions Mock exam.
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.

I think the correct answer is 'e' only but the author indicates that its b,c,e.
Your thoughts will be greatly appreciated. Thanks in advance...
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055

b. You can directly run the garbage collector whenever you want to.

You can suggest to the JVM to run the garbage collector by System.gc(), but that's it.

c. The garbage collector informs your object when it is about to be garbage collected.

I think this is downright wrong. Maybe it was referring to finalize().
Lucy Das
Greenhorn

Joined: Jul 14, 2002
Posts: 8
Thanks Anthony.. appreciate your help.
java doubts
Greenhorn

Joined: Nov 15, 2004
Posts: 1
I too feel only d is correct ans.
You can directly run the garbage collector whenever you want to. This is not true because u can force JVM to invoke it using System.gc()but when it will run depends on JVM.
Sham Grandhe
Ranch Hand

Joined: Dec 16, 2003
Posts: 73
Hi Lucy Das,
This topic is a bit confusing, but if you go throught the materials carfully.

I think that only cis the right answer.

c. The garbage collector informs your object when it is about to be garbage collected.

what i think is GC informs your obj means that you can make sure when actually the GC is running.


when comming to the other points.
b --> as java doubts told is correct.
e --> it may be right because it depends on different situation and algorithms


regards

sham
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
I agree with Lucy:

a. You can directly free the memory allocated by an object.
No way
b. You can directly run the garbage collector whenever you want to.
No, you v=can only request the GC to run. The doc is crystal clear that you can't force the GC to run.
c. The garbage collector informs your object when it is about to be garbage collected.
If they mean finalize(), that does not work if finalize() has already run and cancelled GC eligibility by creating a reference to the object. finalize() is never calleed more than once on any one instance.
d. The garbage collector reclaims an object´┐Żs memory as soon as it becomes a candidate for garbage collection.
No, GC may never run at all.
e. The garbage collector runs in low-memory situations.
Yes, this is in the doc. It is not the only time GC runs, but we are told by the API that the jvm runs GC before throwing an OutOfMemoryError.
Thrown when the Java Virtual Machine cannot allocate an object because it is out of memory, and no more memory could be made available by the garbage collector.

[ January 22, 2005: Message edited by: Mike Gershman ]

Mike Gershman
SCJP 1.4, SCWCD in process
 
Consider Paul's rocket mass heater.
 
subject: Garbage Collection strikes again...