tell JVM to give back memory to OS

H

HK

From Runtime.freeMemory() and Runtime.totalMemory() I
see that my main data structure uses 250MB of
memory. Setting up the data structure is quite
costly and the JVM allocated 1000MB to get
it done. Now the 750MB are reported as free by
the above mentioned method.

I also tried to serialize the data structure
and read it in again, but the result is
only marginally better, i.e. 600MB free after
the data structure is in memory.

Is there any way to tell the JVMs memory
management system to eventually give back
large chunks of free memory to the OS? I know
that malloc() does that if possible.

I am using 1.4.2, but having a solution on with
1.5 (5.0?) would make me switch.

Harald.
 
C

Chris Uppal

HK said:
see that my main data structure uses 250MB of
memory. Setting up the data structure is quite
costly and the JVM allocated 1000MB to get
it done. Now the 750MB are reported as free by
the above mentioned method.

I also tried to serialize the data structure

If you're happy with serialising it, then maybe you could consider breaking
your application into two programs. One that builds the datastructure and
serialises it to disk (then exits) and the other that reads it from disk and
then goes ahead and does useful things with the data.

If the initial structure is expensive to compute, then that might even help
your app start-up faster if you can re-use the result of one "building" pass in
several subsequent runs of your app.

-- chris
 
H

HK

Michael said:
You probably can achieve that with HotSpot#s MaxHeapFreeRatio
command line option: http://java.sun.com/docs/hotspot/VMOptions.html

Thanks for the hint.

Last time I tried, this did not work.
Now I tried again and it kind of works. I have
to call Runtime.gc() a few times "by hand" even
after freeMemory and totalMemory show a
high FreeRatio.

I can only guess that the reason is that a very
small number of objects is created and
destroyed after the big data structure is
up and running.

Any ideas when/how to call GC or is there
still another of the many options of the VM
which may help?

Harald Kirsch
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,438
Messages
2,571,699
Members
48,796
Latest member
Greg L.
Top