• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Memory Managment

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

  • reply
      Bookmark Topic Watch Topic
    • New Topic