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

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



Part I

According to JLS, calling these methods does not guarantee that the gc process
will start. JVM will make an effort to run gc when these methods are called.

Part II

One possible explanation could be:

Since garbage collection is run as separate Thread, JVM can run gc as low
priority process. It may mean that whenever these methods are called JVM
may choose to increase the priority of gc thread and hence are useful.

Hope this helps.

Sudhir


>-- Original Message --
>From: Lee Chalupa <lchalupa@seelink.org>
>To: java certification study group <javacertification@seelink.org>,
>   Atlanta Java Users Group <ajug-members@ajug.org>
>Date: Wed, 13 Nov 2002 10:38:33 -0500
>Reply-To: lchalupa@seelink.org
>Subject: 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
>
>
>
>
>
>
>