Increase java heap size

It could happen sometimes (more often when working with images) that a java program hang up with a java.lang.OutOfMemoryError. This generally happen because there’s not enough space in the heap memory for storing objects.

You can change the heap size or by the Java Control Panel or by the command line. I prefer this last one and here is the syntax

java -Xms<startHeapSize> -Xmx<maximumMeapSize> …

By default values should be -Xms32m -Xmx128m but I often solved with this values

java -Xms32m -Xmx512m …


3 thoughts on “Increase java heap size

  1. You should use it to execute your program. So for example if you have (correctly compiled) with a static void main(…) then, instead of executing the program with

    java MyProgram


    java -Xms32m -Xmx512m MyProgram

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s