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

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 .

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 ...

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.

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.

Related

Problem with Intellij and Heap Size Minimum

I am importing this project
https://github.com/scalaz/scalaz
into the Intellij.
But I get a problem with minimum heap size. I am not sure where the size is beeing set. Any advices to fix this problem please:
/usr/lib/jvm/java-8-openjdk/bin/java -agentlib:jdwp=transport=dt_socket,address=localhost:34077,suspend=n,server=y -Xdebug -server -Xms3784m -Xmx3784m -XX:MaxMetaspaceSize=1g -Xss4m -Xmx1536M -Didea.managed=true -Dfile.encoding=UTF-8 -jar
Error occurred during initialization of VM
Initial heap size set to a larger value than the maximum heap size
Process finished with exit code 1
In preferences of Intellij you can set the maximum heap size for sbt:
This works for me - make sure if you open a new project that you check Use sbt shell for imports and for builds. See my default settings in the screenshot.

How to specify java vm in VM arguments

I have a maven project I want to run it using 64 bit jvm in the project run configuration under VM arguments I set the following
-vm C:/Program Files/Java/jdk1.8.0_60/bin
It says Unrecognized option -vm
Can anyone tell me how to set jvm from VM arguments?
Thanks
As you highlighted in one of your comments, after changing JAVA_HOME to another VM, you are getting a error message saying:
Error occurred during initialization of VM
Could not reserve enough space for 1945600KB object heap
The problem here is that some configuration is setting the -Xms argument to something around 2G or 2048M. Look into your run configuration and remove that setting. If you are experiencing OutOfMemoryError: Java heap space, look at this answer.

Setting Java Heap Size does not work with 256GB RAM 64-bit machine

I have been trying to find the answer to this but I still could not.
I have a 64-bit machine with 256 GB RAM.
I am trying to execute a Java program which links to MySQL. And it needs a quiet big heap size because when I used VM argument -Xmx1024m after few minutes this pops up:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
But, when I tried to set the program VM argument by -Xmx2048m or bigger, it does not work and said:
Error occurred during initialization of VM
Could not reserve enough space for 2097152KB object heap
I read that setting -Xmx2048 is not a problem for 64-bit machine but I really do not know why it's not working on my machine.
java -version output:
wmic OS get FreePhysicalMemory /Value output:
FreePhysicalMemory=251663664
wmic computersystem get TotalPhysicalMemory output:
TotalPhysicalMemory
274811621376
wmic os get osarchitecture output
OSArchitecture
64-bit
I could not execute systeminfo|find "Memory" as it says wrong syntax. Im not sure why either.
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
This message implies the java heap does not have enough space to do further allocation.
It seems you have set to 1G of Xmx which is insufficient for your application
else the application might leak memory which occupies space in java heap.
Error occurred during initialization of VM
Could not reserve enough space for 2097152KB object heap
During VM initialization. JVM does various init right from Heap to JIT modules.
Java heap are continiuos space while doing doing initialization if JVM could not find the
contigous memory space for the requested Xmx then above error message will be thrown.
These are virtual memory allocation so please do not confuse with physical memory values
Please run the command
java -verbose:init -Xmx2048 -version
this command will tell the steps undergoes by JVM while doing initialization and during what step it got failed.
Consider running your app as an administrator - just launch the PowerShell console via right click -> Run as Administrator.
Windows may deny granting a lot of memory to a single process that is running non-elevated.
Also - are you using Windows Server or a workstation version of Windows? It is generally recommended to use Windows Server for such "big" services.

OutOfMemoryError: insufficient memory in IntelliJ?

When I run my project in IntelliJ in debug mode I get the following error.
Does anybody know what is the cause?
I already increased my heap size in idea.vmoptions:
-ea
-server
-Xms1g
-Xmx3G
-Xss16m
-Xverify:none
-XX:PermSize=512m
-XX:MaxPermSize=1024m
I already increased my heap size for compiler to 1024 as bellow:
Try Run menu -> Edit Configurations... -> find your project in the tree of projects on the left, look for VM options: in the panel on the right, and enter something there, according to information found here: What are the -Xms and -Xmx parameters when starting JVM?
That having been said, I should also add that if you are running out of memory without knowingly doing extremely memory hungry stuff, then what you have in your hands is a bug which is causing your program to do runaway memory allocation, which will always be resulting in out-of-memory errors no matter how much you increase your heap size. In that case, you will need to look at your code, not at your project options.
It is very strange still i don't understand why but I resolved it by decreasing the size of VM Options: -Xmx820m.
Maybe because i use jre 32 bit en my Intellij IDE runs on 64 bit.

Out of Memory Exception in java Eclipse

Iam trying a Compiler in my java Eclipse. And I get the error :
Exception occurred during event dispatching:
java.lang.OutOfMemoryError: Java heap space
at java.awt.image.DataBufferInt.<init>(Unknown Source)
How to solve this?
Compiler compiles up to 185 files out of 414 files and then gets the exception. The memory is 1024M
Click on Run configuration in the Eclipse. Choose your application or server tab (which you want to have more memory size).
In the Argument tab, write -Xmx<memory size>. memory size is what you want to set.
set your Virtual Memory Argument
-Xms128M -Xmx1024M -XX:MaxPermSize=128M like this

Categories