File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Memory Managment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Memory Managment" Watch "Memory Managment" New topic
Author

Memory Managment

rogel garcia
Ranch Hand

Joined: Dec 19, 2003
Posts: 41
Everytime someone runs out of memory in java, the people advise to set -Xmx and -Xms to an amount of memory.
I know how this work, but the people allways say to use the same amount in Xmx and Xms like -Xmx256 -Xms256.
Why setting the two paraemters the same ammount is better?
Whats the disadvantage of doing something like this -Xms128 -Xmx256?

Thanks


SCJP 1.4
Pedro Gongora
Greenhorn

Joined: Oct 03, 2003
Posts: 17
if you set an initial heap size lower than it max capacity, at some time jvm will need to do some memory reallocation, and that is time and cpu consuming. i think that's the reason why it's recommended to set both to the same value.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

We had an application designed to run in 1.5Gb memory and we didn't notice any problem in allocating more memory. I don't doubt you, but do you have any more information?

We had to end up setting min and max memory to the same upper limit since we were using Toplinks WeakCacheHardIdentityMap, and this caching strategy would empty the cache before allocating memory, and would never get to the max size otherwise.
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
For a lot of applications, I think it's fine to use a smaller value for -Xms than for -Xmx. That allows the Java application to start off relatively small, but to grow if necessary.

However, there are some situations where this is not true. Here's two: -

  • If your Java application uses lots of Soft/WeakReference caches, then Java will flush these caches, before it increases the heap size. Therefore, with a small initial heap size, you may not get as much benefit from such caches as you would with a bigger initial heap size.
  • If other applications are negotiating for the memory available on the machine, then setting a small initial heap size may allow the other applications to get hold of all the available memory, so that Java cannot increase its heap when it wants to do so. We have this problem with our particular application, so we do set -Xms and -Xmx to the same value.


  • Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Memory Managment
     
    Similar Threads
    initial/maxmum java heap size
    outOfMemory
    JVM process memory VS object heap memory
    convert excel
    Running java jar with ram of 2GB