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

I use Eclipse to run the Java 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 Properties> Run> VM Settings, and I started the program again, I got a new error,

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

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

+6
source share
3 answers

to change the VM for Eclipse, you can change the number of MVs from Windows> Preferences> Java> Installed JREs from there, select the JRE and click "Edit", then write in the default arguments VM: -Xmx1024M or any other amount of memory ...

+7
source

Error initializing virtual machine. Incompatible initial and maximum heap sizes specified

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


netbeans provide -Xms change only from properties> run> VM options

I am not a NetBeans user. However, a brief search of the Using NetBeans 5.0 manual says this is not true:

Configuring JVM Arguments

You can specify the JVM arguments for the project in the Project Properties dialog box. Open the Project Properties dialog box and click Run in the Categories panel. and then enter a list of JVM arguments, separated by spaces, in the VM Parameters field.

In other words, you can install any JVM option supported by the JVM.


here is the line i changed -Xms512m

(Finally he tells us !!)

Add -Xmx512m.

For writing, the general JVM parameters (for example, -Xmx and -Xms) are clearly described on the java command manual page. You must READ IT CAREFULLY.

+2
source

To increase the heap size of the VM, use the -Xmx option, this may solve the problem. But this seems to be your coding issue. Perhaps the code is in a dead loop to create a new object, or a very large object is being created in your code, so I suggest you check the code first.

0
source

Source: https://habr.com/ru/post/909424/


All Articles