From owner-freebsd-java@FreeBSD.ORG Fri Aug 15 21:27:12 2008 Return-Path: Delivered-To: freebsd-java@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 505ED1065678 for ; Fri, 15 Aug 2008 21:27:12 +0000 (UTC) (envelope-from spatula@spatula.net) Received: from mu-out-0910.google.com (mu-out-0910.google.com [209.85.134.188]) by mx1.freebsd.org (Postfix) with ESMTP id CE8058FC08 for ; Fri, 15 Aug 2008 21:27:11 +0000 (UTC) (envelope-from spatula@spatula.net) Received: by mu-out-0910.google.com with SMTP id i2so923296mue.3 for ; Fri, 15 Aug 2008 14:27:10 -0700 (PDT) Received: by 10.103.199.16 with SMTP id b16mr2271067muq.5.1218835630181; Fri, 15 Aug 2008 14:27:10 -0700 (PDT) Received: by 10.102.253.7 with HTTP; Fri, 15 Aug 2008 14:27:10 -0700 (PDT) Message-ID: Date: Fri, 15 Aug 2008 14:27:10 -0700 From: "Nicklas Johnson" Sender: spatula@spatula.net To: "Kees Jan Koster" In-Reply-To: MIME-Version: 1.0 References: <83eb635f0808150545id908826r81346d5b62989570@mail.gmail.com> X-Google-Sender-Auth: 0ae6493b0170c20a Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: freebsd-java@freebsd.org Subject: Re: The aside (was: Crash when running 1.6.0_03) X-BeenThere: freebsd-java@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting Java to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Aug 2008 21:27:12 -0000 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 > 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/