Hi all, I need some help with this question I found in Boone's exam3, 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 My question is that is (b) a good choice because we know that we can only ask the garbage collector to run garbage collection using System.gc or Runtime.gc but it is totally at the discretion of the garbage collector when it wants to reclaim the resources. Hoping to hear from u guys soon, Nandini
Joined: Dec 16, 2000
This is a very ambiguous question. This is debated at least once a week here at JavaRanch. I would say c and e are correct. You can only suggest to run the garbage collector; you can't force it. You have to remember that garbage collection is implemented by the vendor, meaning that it can be slightly different on different jvm's.
Joined: Mar 31, 2001
I think b is a correct answer because we are only running the garbage collector usng System.gc or Runtime.gc The answer choice is not talking about when the resources themselves are reclaimed.
Joined: Feb 04, 2001
Hi Dini... 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 WAY...., you can REQUEST to run, but JVM will not guarantee to execute your request, (may be in the future Java should add a method for GC that returns a "magic word"...PLEEEASE !!!) c.The garbage collector informs your object when it is about to be garbage collected. YES..., by calling it's finalize() method. d.The garbage collector reclaims an object?s memory as soon as it becomes a candidate for garbage collection. NOPE...JVM doesn't guarantee ... even if "Julia Roberts" ask fot it...!! e.The garbage collector runs in low-memory situations. YES...also in medium, High, at the beach, while you sleep, while you eat, what ever..., there is no way you can predict about the behavior of GC. the answer is : c & e