Dynamic memory
The
Xmx
parameter defines the bad x dynamic memory image that the java Virtual Machine will allocate for storing object instances, variable values, among others .
It is important to set a reasonably greater value than the application requires on average to avoid not only OutOfMemory
errors but also memory shortages, otherwise the Garbage Collector will run very frequently and cause pauses unwanted in the program.
Xms
defines the initial amount of dynamic memory allocated at the beginning of the JVM.
It's important to check how much your app uses on average and set a value close to that. This way, your application will not require pauses to allocate memory, resulting in a higher boot performance to the point where the application is running at a steady level.
Permanent memory
Java also has another part of the memory called "static" or "permanent", used to load its classes ( .class
files), internalize Strings, among other things.
As a general rule, permanent memory can not be deallocated. This implies that if your application has many Jars and classes, at some point an PermGen space error will occur.
The error occurs because it is not possible for Java to load new classes when there is no space in the permanent memory, since it is not possible to discard classes already loaded to make room for new ones.
Here are the other two parameters. The XX:MaxPermSize
defines the maximum amount of permanent memory that the Virtual Machine can use. XX:PermSize
sets the initial size of it.
Example
The following image illustrates the above concepts:
Notethatinthedynamic(left)memorypartthereisstilladifferencebetween"new" and "old" generation, which are used, respectively, to store newly created objects that are candidates and be deallocated quickly from objects created there more time, with less chance of deallocation.