Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 15 Aug 2008 14:27:10 -0700
From:      "Nicklas Johnson" <freebsd@spatula.net>
To:        "Kees Jan Koster" <kjkoster@kjkoster.org>
Cc:        freebsd-java@freebsd.org
Subject:   Re: The aside (was: Crash when running 1.6.0_03)
Message-ID:  <be800d230808151427i31356e25ue0ab3b5b12cd50e8@mail.gmail.com>
In-Reply-To: <D1040195-38EE-43DD-A2C0-5CE2DBBA8218@kjkoster.org>
References:  <83eb635f0808150545id908826r81346d5b62989570@mail.gmail.com> <be800d230808150756k55fcc019ga1713362db0a2d9a@mail.gmail.com> <D1040195-38EE-43DD-A2C0-5CE2DBBA8218@kjkoster.org>

next in thread | previous in thread | raw e-mail | index | archive | help
There are many reasons not to call System.gc():

1. It only "suggests" that the GC do collection, and can be completely
ignored... so if you're relying on some behaviour out of gc(), you're likely
to see unexplained and unpredictable breakage across platforms.
2. Modern GCs are clever enough to know when is a good time to collect
garbage; calling System.gc is more likely to reduce performance versus just
letting the GC do its job.
3. On some platforms (like Sun's JVM), System.gc() will result in a *major*
collection happening, which is probably more than what you want (and usually
an order of magnitude slower).

You're far better off *tuning* the garbage collector and heap sizes rather
than explicitly trying to invoke the garbage collector.

See also:

http://java.sun.com/docs/hotspot/gc/index.html
http://java.sun.com/docs/hotspot/HotSpotFAQ.html#gc_pooling
http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html#1.1.Other%20Considerations|outline

2008/8/15 Kees Jan Koster <kjkoster@kjkoster.org>

> Dear Nicklas,
>
>  As an aside, it's a really, really bad idea to ever call System.gc()
>> directly in a modern JVM.  It's much better to leave it to the JVM to
>> decide
>> when to do garbage collection.
>>
>
> Interesting. Could you elaborate on this? What makes doing a manual gc() so
> bad? Any documents on the 'web that talk about this in detail?
>
> --
> Kees Jan
>
> http://java-monitor.com/forum/
> kjkoster@kjkoster.org
> 06-51838192
>
> Rule 1 for being in a hole: stop digging.
>
>


-- 
"Courage isn't just a matter of not being frightened, you know. It's being
afraid and doing what you have to do anyway."
-- Doctor Who - Planet of the Daleks
This message has been brought to you by Nick Johnson 2.3b1 and the number 6.
http://healerNick.com/ http://morons.org/ http://spatula.net/



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?be800d230808151427i31356e25ue0ab3b5b12cd50e8>