[intellij-idea] How can I give the Intellij compiler more heap space?

When I make an Intellij project, I keep getting the following out of memory error.

I already increased my heap size in idea.vmoptions:

-Xms128m
-Xmx2048m
-XX:MaxPermSize=1024m
-XX:ReservedCodeCacheSize=64m
-ea

But I still get this error:

Information:The system is out of resources.
Information:Consult the following stack trace for details.
Information:java.lang.OutOfMemoryError: Java heap space
Information:    at com.sun.tools.javac.util.Position$LineMapImpl.build(Position.java:139)
Information:    at com.sun.tools.javac.util.Position.makeLineMap(Position.java:63)
Information:    at com.sun.tools.javac.parser.Scanner.getLineMap(Scanner.java:1105)
Information:    at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:512)
Information:    at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:550)
Information:    at com.sun.tools.javac.main.JavaCompiler.parseFiles(JavaCompiler.java:804)
Information:    at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:727)
Information:    at com.sun.tools.javac.main.Main.compile(Main.java:353)
Information:    at com.sun.tools.javac.main.Main.compile(Main.java:279)
Information:    at com.sun.tools.javac.main.Main.compile(Main.java:270)
Information:    at com.sun.tools.javac.Main.compile(Main.java:69)
Information:    at com.sun.tools.javac.Main.main(Main.java:54)
Information:    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Information:    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
Information:    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
Information:    at java.lang.reflect.Method.invoke(Method.java:597)
Information:    at com.intellij.rt.compiler.JavacRunner.main(JavacRunner.java:71)
Information:Compilation completed with 1 error and 0 warnings
Information:1 error
Information:0 warnings
Error:Compiler internal error. Process terminated with exit code 3

What am I missing?

This question is related to intellij-idea

The answer is


I was facing "java.lang.OutOfMemoryError: Java heap space" error while building my project using maven install command.

I was able to get rid of it by changing maven runner settings.

Settings | Build, Execution, Deployment | Build Tools | Maven | Runner | VM options to -Xmx512m


I had a similar problem with Ant build (started by hand from IDEA GUI). In my case there was the right solution to right click on the Ant task, choose properties and set a higher value to "Maximum heap space (Mb):" and "Maximum stack space (Mb):" input fields.

enter image description here


GWT in Intellij 12

FWIW, I was getting a similar error with my GWT application during 'Build | Rebuild Project'.

This was caused by Intellij doing a full GWT compile which I didn't like because it is also a very lengthy process.

I disabled GWT compile by turning off the module check boxes under 'Project Structure | Facets | GWT'.

Alternatively there is a 'Compiler maximum heap size' setting in that location as well.


I like to share a revelation that I had. When you build a project, Intellij Idea runs a java process that resides in its core(ex: C:\Program Files\JetBrains\IntelliJ IDEA 2020.3\jbr\bin). The "build process heap size", as mentioned by many others, changes the heap size of this java process. However, the main java process is triggered later by the Idea's java process, hence have different VM arguments. I noticed that the max heap size of this process is 1/3 of the Idea's java process, while min heap is the half of max(1/6). To round up:

When you set 9g heap on "build process heap size" the actual heap size for the compiler is max 3g and min 1,5g. And no need for restart is neccessary.

PS: tested on version 2020.3


To resolve this issue follow the below given steps-

1). In inteli Go to File> Setting Option and Search for Vm Option In the field of Vm Option for Importer give value -Xmx512m. Intelij Setting Options

2). Go to Control Pannel Select View by :Large icons then Go to Java one promp window will appear with name java control pannel then go to java Java VM Options

select view option. java view options

In Java Run time Environment Setting pass Run time Parameters as -Xmx1024m.

3). If above given options does not work then change the size of pom.xml


Since IntelliJ 2016, the location is File | Settings | Build, Execution, Deployment | Compiler | Build process heap size.

enter image description here


There is a

idea64.exe

starter in

IntelliJ IDEA 13.1.5\bin

so you can address more space.


In my case the error was caused by the insufficient memory allocated to the "test" lifecycle of maven. It was fixed by adding <argLine>-Xms3512m -Xmx3512m</argLine> to:

<pluginManagement>
  <plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.16</version>
        <configuration>
            <argLine>-Xms3512m -Xmx3512m</argLine>

Thanks @crazycoder for pointing this out (and also that it is not related to IntelliJ; in this case).

If your tests are forked, they run in a new JVM that doesn't inherit Maven JVM options. Custom memory options must be provided via the test runner in pom.xml, refer to Maven documentation for details, it has very little to do with the IDE.