On Thu, 21 Feb 2008, Mika Nystrom wrote:

> Out-running the garbage collector? I'm not used to Java, but in
> Modula-3, the garbage collector gets called when you allocate memory,
> is that not how it works in Java?


In a word, no. Garbage collection in Java is asynchronous. In the Sun
JVM there are several different garbage collection strategies. The
default strategy uses multiple "generations"-- a "new" generation for
short-lived objects; those objects that live through a new generation
collection get promoted to one of many "survivor" spaces, and those that
survive collection there (either because of time or exhausting the size of
the survivor space) get promoted to the "tenured" or "old" generation.
Then there's a "permanent" generation for classes and other stuff.

If you just sit and watch the memory size of a JVM process, it might
appear to be "leaking" memory, but what's happening under the hood is far
more complicated than that. The JVM will also grow to accomodate the
amount of memory it has needed to allocate, but won't necessarily -shrink-
again once those objects are garbage collected. In a long-running
process, chances are that if a program needed 256M once, it's going to
need it again.

To get a real good idea of what's going on under the hood, look at tools
like jvmstat and visualgc.

This document will give you a much more detailed view than my rough
outline here:

http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html

Nick


--
"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/
_______________________________________________
freebsd-java@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-java
To unsubscribe, send any mail to "freebsd-java-unsubscribe@freebsd.org"