Java Memory Allocation:Heap Space Error

Introduction and Reason:

image001

java.lang.OutOfMemoryError: Java heap space

Java applications are allowed to use a limited amount of memory. This limit is specified during application startup. To make things more complex, Java memory is separated into two different regions. These regions are called heap space and permgen:

image003

The size of those regions is set during the Java Virtual Machine (JVM) launch by specifying parameters such as -Xmx and -XX:MaxPermSize. If you do not explicitly set the sizes, platform-specific defaults will be used.

So – the “java.lang.OutOfMemoryError: Java heap space” error will be triggered when you try to add more data into the heap space area, but there is not enough room for it.

Note that there might be plenty of physical memory available, but if the heap size limit for this Java program has been hit, the “java.lang.OutOfMemoryError: Java heap space” error is thrown.

Cause of java.lang.OutOfMemoryError

There most common reason for the java.lang.OutOfMemoryError: Java heap space error is simple. You are trying to fit an XXL application into a S-sized Java heap space. That is – the application just requires more Java heap space to operate normally. Other causes for this OutOfMemoryError message are more problematic and are caused by a programming error:

  • Spikes in usage/data volume. The application was designed to handle a certain amount of users or a certain amount of data. Now, when the number of users or the volume of data suddenly spikes, the operation which functioned normally before the spike ceases to respond and triggers the java.lang.OutOfMemoryError: Java heap space error.
  • Memory leaks. A particular type of programming error will lead your application to constantly consume more memory. Every time the leaking functionality of the application is used it leaves some objects behind into the Java heap space. Over time the leaked objects consume all of the available Java heap space and trigger the already familiarjava.lang.OutOfMemoryError: Java heap space error.

 [divider]

The following points are worthy to note on this error:

  1. Once we achieve to the state of heap space error the system wont function further as no memeory is available for the functioning.
  2. The WebUI of Enterprise 2.0 wont even let you login in the client and the desktop client also .
  3. In Order to check the error we need to check the console that will tell us the error.
  4. Once we attain the error we have to close the server and restart it as there is no other way round.

Solution for java.lang.OutOfMemoryError

The first solution should be obvious – when you have ran out of a particular resource, you should increase the availability of such a resource. In our case: when your application does not have enough Java heap space memory to run properly, fixing it is as easy as altering your JVM launch configuration and adding (or increasing if present) the following:

-Xmx1024m

In order to increase the memory in Enterprise 2.0 you need to follow the following steps:

  1. Increase the Heap Space memory in E2, You have to change the Xmx variables in following files:
  2. Open in notepad and search Xmx and Edit.
  3. AdempiereEnv open in notepad and edit
  4. AdempiereEnv.properties

[divider]

These 2 files are placed in Ossagho folder when u extract the build.

  1. Run.bat – Right click and edit the file
  2. While editing the file keep the Xms and Xmx in proportion i.e if we double the mimimum we also have to double the maximum limit .
  3. The default values are Xms – 64M and Xmx – 512M , and we can increase them to any values till RAM supports changes.
  4. Some sample values which can be feeded are:

i.      Xms 128M                     Xmx 1024M

ii.      Xms 192M                     Xmx 1536M

  1. Once we change the values in both the files we need to run silentSetup of Adempiere which will reflect all the values in the E2 Server and all changes are enforced.
  2. Restart the server and we will notice that console shows updated Values.

 

 

                                                                                                                        -Adempiere Support {India Portal}

About This Author

Post A Reply