What is the advantage of fixed heap size i.e. -Xms = -Xmx

Viewed 805

My application is using fixed heap size i.e. -Xms = -Xmx but even after some Googling I couldn't understand what is the advantage of fixed heap size. If any JVM expert could please throw some light on it.

1 Answers

If you keep -Xms the same as -Xmx then a couple of things happen:

  1. Right from the start you will get the same heap size committed to the virtual machine (JVM).
  2. Since it is a fixed heap so JVM will never grow or shrink the heap, which is what usually happens after each GC cycle if -Xms is not same as -Xmx.

I am not sure if there is any real advantage in this but I think it is just that you get a controlled environment where you get a good heap size right from the start (which is mentioned in the Oracle docs).

When you should use fixed heap size?

From Oracle docs: if you know the heap size requirement of your application then you should use fixed heap size otherwise you should go with either of the options - (1.) use -Xmx and -Xms (2.) don't use -Xmx and -Xms, and instead specify the garbage collector you want to use and it will grow and shrink the heap.

Related