java.lang.OutOfMemoryError: Java heap space in IntelliJ - java

I have imported a SBT project into IntelliJ(version 14). When I am trying to run something in the terminal, the console output is giving me "java.lang.OutOfMemoryError: Java heap space".
I have tried increasing the size (Xms2048m, Xmx2048m) in *.vmoptions, and also in the IDE build settings of SBT project. I have restarted my machine as well. Nothing is working out.
Any more inputs on it other than the things I have tried ?
P.S: I am running the project through the activator. When I am doing it from IntelliJ command prompt it's throwing me the error, but when I run the activator from windows command prompt, it is successfully running the application.

You just asked your IDE:
-Xms2048m - ask VM to allocate 2048MB (2GB) heap on start
-Xmx2048m - limit heap to 2048MB
The reason could be:
You tried to exceed 2048MB
Allocating 2048MB on start was not possible (you probably just went out of RAM)
System thought so fast allocation was a malware.

I think you will need to provide the memory settings as parameters to the command you are running on the console.
To the best of my knowledge any parameters set inside IntelliJ will only be for use of IntelliJ itself, and when you run the project from the SBT window (I am assuming it works like the maven window).
Also as far as I know the terminal window in IntelliJ is just a "pass through" to the underlying console of the host system.
Not sure you need it, but this seems to be a good explanation of the memory settings, and links to duplicate answers: What are the Xms and Xmx parameters when starting JVMs?

I was getting a similar issue while building the project in IntelliJ what worked for me is to update the build memory size in settings as below:
Settings (or Preferences) -> Build, Execution, Deployment -> Compiler -> Shared build process heap size (Mbytes)

Related

Intellij occasionally unable to reserve enough space for object heap

RESOLVED check below for solution.
I'm using Intellij Idea 2017.2.2. Below is my intellij Specs.
My Intellij would only occasionally fail a maven build or a jboss server start with the error
Error occurred during initialization of VM
Could not reserve enough space for 1048576KB object heap
If I were to run the maven build with the vm args of
-Xms512m -Xmx1024m
The build would fail 9 out of 10 times (not exactly every 10th, but just randomly). But on the 10th time it would work. I simply have to keep pressing the install button until it works.
This was a major problem before was that if I don't specify the vm args then the build would go about halfway then fail on running out of java heap space.
The same exact behavior can be observed for my jboss server (JBOSS6.4 - 7.5.0.Final redhat 21), where the server would fail to start 9 out of 10 times. Then start up as randomly as it does not.
Specs
IntelliJ IDEA 2017.2.2
Build #IU-172.3757.52, built on August 14, 2017
Licensed to -----
Subscription is active until May 31, 2018
JRE: 1.8.0_152-release-915-b10 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 7 6.1
What I tested
I upgraded from Intellij 2017.1 to 2017.2 and the behavior did not change.
I also tried to do the same on Eclipse which also did not help.
Clean restart of PC, then close all the unnecessary apps, open intellij do a maven build and yet it fails, but a few more clicks and it works inconsistently as usual. (note at this moment only 6gb out of 16 is used, there is no way there is an insufficiency with memory)
*Edits
This PC have 16 gb of ram. While the fails are happening about 9.5GBs are being used at that moment.
Ultimately I was able to resolve the issue by updating the proper JDK.
My project was picking up on an incorrect JDK and hence was running the 32 Bit as opposed to 64 bit JDK.
Simply added the correct JDK under File > Project Settings.
It seemed that my project never required that much memory before, but once the need had risen, it seems that a 64 bit became required.
I have solved this problem by changing the build settings in Intellij.
Please follow the below steps.
For SBT:
1. Go to File -> Settings -> Build, Execution Deployment -> sbt
2. Change the value of Maximum heap size, MB to your available memory. Ex. 512
(Previously this value was 1536, due to this I faced the problem)
For Maven:
1. Go to File -> Settings -> Build, Execution Deployment -> Maven -> Importing
Change the value of VM options for importer to your available memory. Ex. -Xmx512m
I had to do the following options to get it pass the error.
Spec used: IDEA IntelliJ 2019.3.5 (Community Edition)
Increase the memory in IntelliJ VM Options
Step 1:
Go to Help -> Edit Custom VM Options
Step2: Change the Heap sizes as given below
Run the app with increased memory by setting the VM options
Run -> Edit Configurations
My issue was resolved by installing Visual C++ Redistributable Packages:
https://aka.ms/vs/16/release/vc_redist.x64.exe

PermGen size error while generating Cobertura Report

I ram running into issue where my application throws PermGen size error whenever I generate cobertura report using this command clean cobertura:cobertura. I have the tried almost everything such as the following:
Increase permgen size in sts.ini
Increase permgen size in jdk vm argumemts by going into Windows -> Preferences
-> Java -> Installed JREs -> click jdk -> edit and on the vm args
Increase permgen size in maven.bat file
Some in stackOverFlow recommended to mention the version in surefire plugin and I have that in place already
None of the above is helping me at all. I am using Mock/PowerMock objects a lot in my JUnit test cases. Maven test runs perfectly fine.
How can I fix this issue?
Thanks
Since you tried to change sts.ini, I'm assuming you are running it from inside STS. Even when Maven is kicked off by STS, it runs in a separate process from STS, so changing sts.ini wouldn't help. you need to set the MAVEN_OPTS with the increased permgen size in the run configuration for the mvn job.
set MAVEN_OPTS.
Value will be: -Xms1024m -Xmx3000m -XX:MaxPermSize=1024m
export MAVEN_OPTS="-Xms1024m -Xmx3000m -XX:MaxPermSize=1024m" //unix
set MAVEN_OPTS="-Xms1024m -Xmx3000m -XX:MaxPermSize=1024m" //window

IntelliJ set heap size over 4GB. How to?

I'm using IntelliJ 14.3 on x64 Java. Available memory: 10Gb (out of 16Gb total RAM)
(Basically set -Xmx8000M or greater)
The problem is I need more than 4Gb memory to use for an App.
I can not find any answer or solution to my problem and I've looked for days.
I've been looking on stackoverflow for people asking the same question, but they had problems with the default value -Xmx512M and they kept linking to other answers, linking to another answer (waste of time and no solution so far).
I tried the following things that did not work:
Modifying the idea64.exe.vmoptions file for IntelliJ: didn't seem to do anything, no error, no memory increase, nothing. (it seemed as it ignored the file)
Using JAVA_OPTIONS in Environment Variables: Made IntelliJ crash on startup or freeze without using more memory than before.
Tried it with a lower value, of 1512M, same heap size problem
A fresh installation, even of the 15.x version of IntelliJ: nothing changed.
*Note:
someone at my workplace can set it in IntelliJ to work (but we can't figure out how
Running the class in command line with that -Xmx8000M seems to work, but I want to set it in IntelliJ for easy use
If anyone ran into this issue and can suggest solutions, I politely ask them to do so.
What worked for me was the following:
Help -> Edit Custom VM Options, change to -Xmx8000M
restart IntelliJ
Run -> Edit Configurations -> Application -> your main class -> Configuration,
add -Xmx8000M in the VM Options field.
Doing only 1) or 3) but not both didn't work for me.
Adding -Xmx10000M option to the bellow location worked for me:
"Intellinj Idea -> Run -> Edit Configuration -> Modify Options -> Add VM Option"
To specify the memory used by the app, specify the needed -Xmx option in the "VM options" field of the run configuration you use to start the app from IntelliJ IDEA.

Easily run out of memory when use Eclipse and Ant/Junit on my Mac

Now that OSX Maverick works with memory different (so it seems and from what I've read), when I run Java as a separate JVM (Ant/JUnit/etc.), I often get OutOfMemory exceptions as it bases the max heap on memory available which is usually close to zero (because that's apparently how Maverick works?). I know I can set the max heap space using the -Xmx argument for a run or external tool configuration in Eclipse, but that is a pain when I have several possible configurations that can be run.
I believe I would have to run in a separate JVM so my configurations don't get polluted with Eclipse classpath JARs and to a smaller extent, so the Eclipse JVM doesn't get polluted with configuration runs and all the class loading that goes on.
Is there a global setting to set the max heap available for all JVMs launched by Eclipse? For Ant, I tried setting ANT_OPTS in my environement to "-Xm1024m", but that setting doesn't seem to take when running Ant through Eclipse. If I run Ant from the command line directly, it does seem to work (or at least I didn't get an exception). When running Ant in verbose+debug mode in Eclipse, I do see "Setting project property: env.ANT_OPTS -> -Xmx1024m" so I know the variable is set.
I ran Java VisualVM to get a better idea what is going on, this is what it has:
JVM: Java HotSpot(TM) 64-Bit Server VM (23.25-b01, mixed mode)
Java: version 1.7.0_25, vendor Oracle Corporation
Java Home: /Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/jre
JVM Flags: <none>
Main class: org.eclipse.ant.internal.launching.remote.InternalAntRunner
You can configure JVM arguments for an Eclipse Ant build in the Run > External Tools > External Tools Configurations dialog in the JRE tab.
Note that the default is actually to run Ant in the same JVM as Eclipse (which makes some additional Eclipse tasks available).
Running VisualVM made me realize Eclipse was still using 1.7.0_25 and not 1.7.0_45 which is the latest I have installed. Once I updated Eclipse to use 1.7.0_45, I no longer have the issue as the VM does indeed use 1/4 of total memory. Would be nice to know for sure, but it seems like build 25 had a bug or something.

Eclipse won't start

when trying to start eclipse, i receive the message in the image.
when trying to start other instance of eclipse, i receive a message saying: "failed to create the java virtual machine".
How can i solve it?
try starting eclipse with -clean option
./eclipse -clean
If it still doesn't start check ".log" file for error. This file should be located in "workspace/.metadata" folder. Publish error from log to your question.
Also check Java version and JAVA_HOME and PATH on your system are set accordingly. Java version should be at least 1.5
The message "failed to create the java virtual machine" usually implies the failure to allocate enough memory for starting the JVM. This is often due to unavailability of sufficient contiguous free memory in RAM, or incorrect min and max heap sizes.
From the screenshot, it appears that the problem might not be with the min and max heap sizes, so you might want to take a look at the amount of free memory available when starting Eclipse (although that is no indicator of whether all free memory is contiguous).
To begin fixing this issue, you could start Eclipse from the command-line and observe the error messages reported if any. Then you could proceed to calibrate the JVM settings that are better suited to your installation (heavy plugins will require more memory), or change to another JVM.
See also
Why does Eclipse crash with Xmx, XX:MaxPermSize above certain values?
What are the best JVM settings for Eclipse?
Go to C:\Program Files\Java\jre6\bin\client\ and make sure that jvm.dll exists there.
Either way, you might want to try re-installing or updating Java on your machine.
To modify file eclipse/eclipse.ini, try a smaller number in attribute -Xmx, and restart.
Check your version of Java. Oracle accidentally broke Eclipse when they updated the vendor field from 'Sun Microsystems' to 'Oracle'.
http://insideria.com/2010/08/oracle-breaks-eclipse-and-flex.html
Oracle was nice enough to change it back and release an update, which fixes Eclipse.
I had a similar problem when I installed JDK 64-bit version with an install of Eclipse 32-bit (didn't realize it until much searching and searching). Simple solution, but a shot none-the-less.

Categories

Resources