Will system.gc() force garbage collection?

what impact will the method system.gc() have if i call it in one of the user methods.
[92 byte] By [Dhar@9a] at [2007-10-3 5:36:17]
# 1

Hi,

I'm not an expert on this, but I have read the following in an Perf Guide written by HP.

--

Should we see an entry in this data that has the content:

揊ull GC required ?reason : call to System.gc() or Runtime.gc()?br>

then we know that either the user抯 Java code or some library or infrastructure code being used in the application is making an explicit call to the garbage collector. This should never be done. We can cure this problem by removing the call to System.gc() or Runtime.gc() from the code, or by overriding it with the JVM option 朮X:+DisableExplicitGC, as follows:

So...I guess you might want to consider using this call?

caplm_71a at 2007-7-14 23:43:50 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

Found this in another thread.

-

In the Java source code you can find the following comment:

// We don't want shrink all the way back to initSize if people call

// System.gc(), because some programs do that between "phases" and then

// we'd just have to grow the heap up again for the next phase. So we

// damp the shrinking: 0% on the first call, 10% on the second call, 40%

// on the third call, and 100% by the fourth call. But if we recompute

// size without shrinking, it goes back to 0%.

--

caplm_71a at 2007-7-14 23:43:50 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3
> what impact will the method system.gc() have if i> call it in one of the user methods.In every Sun VM back to at least 1.3 and probably before, garbage will be collected.Was there something specific that you had in mind?
jschella at 2007-7-14 23:43:50 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 4
I thought that it suggests that the JVM run a garbage collection.[url] http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html#gc()[/url]Message was edited by: CaptainMorgan08
CaptainMorgan08a at 2007-7-14 23:43:50 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 5

> I thought that it suggests that the JVM run a

> garbage collection.

>

> [url]http://java.sun.com/j2se/1.5.0/docs/api/java/lang

> /System.html#gc()[/url]

>

As I said, in every Sun VM back to at least 1.3 it does collect garbage when you call it.

The VMs by other vendors might choose to do it differently.

jschella at 2007-7-14 23:43:50 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 6

If you use Sun's HotSpot 1.5.0 JVM (or later) with the -XX:+UseConcurrentMarkSweepGC (low-latency) garbage collector, you can use the additional flag -XX:+ExplicitGCInvokesConcurrent to have calls to System.gc() initiate a concurrent collection, rather than cause a stop-the-world compacting collection, which calling System.gc() usually does. Most people who run the low-latency collector are trying to avoid the pauses caused by compacting collections.

If you have some annoying third-party library that calls System.gc() and that upsets your application's performance, you can use the additional flag -XX:+DisableExplicitGC to make calls to System.gc() into no-ops. That works with whatever collector you are using.

Peter.Kessler@Sun.COMa at 2007-7-14 23:43:50 > top of Java-index,Java HotSpot Virtual Machine,Specifications...