[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Certification study group issue: Will the Garbage Collector pick up the rubish is you call it?




Can someone give me an Amen on this issue?  There are two parts to this issue

Part I:

An issue that came out of last night's meeting was from the following question:

"The method System.gc forces the garbage collection process to run."

True or False.

We are not sure.

Here is the research that I have found on the topic:

Mike Meyers has published a few editions of his certification book.
Mike Meyer's book states:  "You cannot force the garbage collector to reclaim memory."

He explains elsewhere: "While you cannot force the garbage collector to reclaim memory, you can suggest that it 
do so by calling the java.lang.System.gc() method or the java.lang.Runtime,getRunTime().gc() method.  Both of these 
methods send a request to the garbage collector asking it to reclaim memory. The garbage collector can honor or 
ignore the request at its whim.

I assume in other words this means that the garbage collection can just ignore the request and refuse to run.


Here is another post I found on a java web site.  I have no idea how credible this source is.
" System.gc() does not mean the garbage collector is called, it only suggests that the VM call it."


Part II:

Ok. If the answer is True, then what is the value of invoking a method that has the discretion to
run or not run.  If it wanted to run it would run without me invoking the method in the first place wouldn't it?


Thanks for the help.


Lee Chalupa