, , , ,

memoryOne common indication of a memory leak is the java.lang.OutOfMemoryError exception. Usually, this error is thrown when there is insufficient space to allocate an object in the Java heap and the garbage collector cannot make space to accommodate a new object, and the heap cannot be expanded further. Also, this error may be thrown when there is insufficient native memory to support the loading of a Java class.

If the java.lang.OutOfMemoryError is due to heap problem, a common solution to this error can be manage the memory allocation pool manually for a Java Virtual Machine by using x options previous to run you application.

The flag Xmx specifies the maximum memory allocation pool for a Java Virtual Machine (JVM), while Xms specifies the initial memory allocation pool.

This means that your JVM will be started with Xms amount of memory and will be able to use a maximum of Xmx amount of memory. For example, starting a JVM like below will start it with 128MB of memory, and will allow the process to use up to 1024MB of memory:

java -Xms128m -Xmx1024m

The memory flag can also be specified in multiple size units, such as kilobytes, megabytes, and so on.


The default value of Xmx will depends on platform and amount of memory available in the system.

When using these settings, keep in mind that these settings are for the JVM’s heap, and that the JVM can/will use more memory than just the size allocated to the heap. From Oracle’s Documentation:

Note that the JVM uses more memory than just the heap. For example Java methods, thread stacks and native handles are allocated in memory separate from the heap, as well as JVM internal data structures.

Notice: The -X options are subject to change without notice.


Jorge Fernandes is Bachelor in Computer Science experienced in telecommunications, security, banking and programmer since 1984. He works in Valhala Networks focused on high-level decisions about scientific and technological policies and strategies of projects oriented to develop web and standalone applications, as well as smart solutions at mobiles. He always oriented to produce innovator products.