S
Simon Brooke
Chris Uppal said:Lew wrote:
[me:]But it's not a requirement (of the OS) that the user should have to
tell it how much memory the app is going to use in advance. The JVM's
inflexibility in this is somewhat puzzling -- I have no other
implementations of GC-ed languages which share this odd
requirement[*].
I have watched the 1.4 JVM grab memory until it uses well over 1GB,
absent
setting a limit with -Xmx. That indicates to me that the JVM will take
*all* available memory by default.
If it did work like that then it would never be possible cure an
out-of-memory condition by setting an explicit max -- only to create one.
BTW, the amount of memory the OS reports the JVM to be using is not
particularly closely tied to how much it is actually using (and
especially not to how much it is using for actual objects), and is even
less tightly tied to the min/max parameters (whether the defaults or set
explicitly).
However, and more seriously, if you are hitting out of memory problems you
need to understand why. If something in your application is chewing up
memory, then ultimately however much memory you allocate it is going to
run out. Some programs - or their working data sets - simply are large,
and that's OK. But as long as something in your application is holding a
pointer to a piece of data the garbage collector cannot collect it, so,
e.g., when building complex persistent recursive structures it's important
to remember to set null things you no longer need.