S Gaber
S Gaber

Reputation: 1560

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

I'm using Eclipse to run java program class, while I run it i got this error

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

then i changed the VM from the Properties > Run > VM Options, and I run the program again i got a new error,

Error occurred during initialization of VM
Incompatible initial and maximum heap sizes specified

I'm trying to apply stanford libraries in my program, any idea how to solve this error .

Upvotes: 6

Views: 29089

Answers (3)

S Gaber
S Gaber

Reputation: 1560

to change the VM for Eclipse you can change the amount of the MV from Windows> Preferences> Java> Installed JREs from there select the JRE and click edit, then write in the Default VM Arguments: to -Xmx1024M or any other amount of memory ...

Upvotes: 7

Stephen C
Stephen C

Reputation: 719679

Error occurred during initialization of VM. Incompatible initial and maximum heap sizes specified

This probably means that you supplied both -Xms and -Xmx options, and the -Xms (initial heap size) value is larger than the -Xmx (maximum heap size) value.


netbeans provide to change the -Xms only from Properties > run > VM options

I'm not a NetBeans user. However, a brief search of the Using NetBeans 5.0 manual says this is not correct:

Setting JVM Arguments

You can specify JVM arguments for the project in the Project Properties dialog box. Open the Project Properties dialog box and click Run in the Categories pane and then type a space-separated list of JVM arguments in the VM Options field.

In other words, you can set any JVM option that your JVM supports.


here is the string that i changed -Xms512m

(Finally he tells us!!)

Add -Xmx512m as well.

For the record, the common JVM options (such as -Xmx and -Xms) are clearly documented in the manual page for the java command. You should READ it CAREFULLY.

Upvotes: 2

Gabry Gao
Gabry Gao

Reputation: 29

To enlarge the VM heap size use -Xmx option, this could solve the error. But it seems it's your coding problem. Perhaps code is in a dead loop to create new object, or a very large object is created in you code, so I suggest you to check code first.

Upvotes: 0

Related Questions