Hi all,
Question 65 in the Boone exam ...
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 official answer is (b), (c), (e).
(c) and (e) make sense to me, but (b) seems questionable ...
Mughal and Rasmussen say "Java does provide facilities to invoke the garbage collection explicitly. The System.gc() method can be used to force garbage collection, and the System.runFinalization() method can be used to run the finalizers for objects eligible for garbage collection."
but, ... Brogden says "The programmer can suggest to the JVM that now is a good time to run garbage collection with one of the following method calls, but there is no guarantee that the JVM will do it: System.gc(); / Runtime.getRuntime().gc();"
also, ... in the JDK docs for System.gc() it says "Runs the garbage collector. Calling the gc method suggests that the
Java Virtual Machine expend effort toward recycling unused objects in order to make the memory they currently occupy available for quick reuse."
I'm confused - (news flash :-) ... Can someone help me out? Can you, are can't you run garbage collection whenever you want?
Thanks a lot!
Greg