How to increase Heap size of JVM

Java

Java Problem Overview


I am getting the following error:

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
        at SQLite.Vm.step(Native Method)
        at SQLite.Database.get_table(Database.java:314)
        at SQLite.JDBC2z.JDBCStatement.executeQuery(JDBCStatement.java:120)
        at SQLite.JDBC2z.JDBCStatement.executeQuery(JDBCStatement.java:168)
        at TestData.readData(TestData.java:21)
        at TestData.main(TestData.java:41)

Java Solutions


Solution 1 - Java

Following are few options available to change Heap Size.

-Xms<size>        set initial Java heap size
-Xmx<size>        set maximum Java heap size
-Xss<size>        set java thread stack size


java -Xmx256m TestData.java

Solution 2 - Java

Java command line parameters

-Xms: initial heap size
-Xmx: Maximum heap size

if you are using Tomcat. Update CATALINA_OPTS environment variable

export CATALINA_OPTS=-Xms16m -Xmx256m;

Solution 3 - Java

Start the program with -Xms=[size] -Xmx -XX:MaxPermSize=[size] -XX:MaxNewSize=[size]

For example -

-Xms512m -Xmx1152m -XX:MaxPermSize=256m -XX:MaxNewSize=256m

Solution 4 - Java

By using the -Xmx command line parameter when you invoke java.

See http://download.oracle.com/javase/6/docs/technotes/tools/windows/java.html

Solution 5 - Java

Use -Xms1024m -Xmx1024m to control your heap size (1024m is only for demonstration, the exact number depends your system memory). Setting minimum and maximum heap size to the same is usually a best practice since JVM doesn't have to increase heap size at runtime.

Solution 6 - Java

-XmxSIZE

For example: -Xmx1024M

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDhananjay JoshiView Question on Stackoverflow
Solution 1 - JavaoliholzView Answer on Stackoverflow
Solution 2 - Javaa--View Answer on Stackoverflow
Solution 3 - Javaspot35View Answer on Stackoverflow
Solution 4 - JavapapView Answer on Stackoverflow
Solution 5 - JavamichaelliuView Answer on Stackoverflow
Solution 6 - JavaNulldeviceView Answer on Stackoverflow