How can I give the Intellij compiler more heap space?

Intellij Idea

Intellij Idea Problem Overview


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?

Intellij Idea Solutions


Solution 1 - Intellij Idea

Current version:

Settings (Preferences on Mac) | Build, Execution, Deployment | Compiler | Build process heap size.

Older versions:

Settings (Preferences on Mac) | Compiler | Java Compiler | Maximum heap size.

Compiler runs in a separate JVM by default so IDEA heap settings that you set in idea.vmoptions have no effect on the compiler.

Solution 2 - Intellij Idea

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

enter image description here

Solution 3 - Intellij Idea

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

Solution 4 - Intellij Idea

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

Solution 5 - Intellij Idea

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.

Solution 6 - Intellij Idea

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

Solution 7 - Intellij Idea

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.

Solution 8 - Intellij Idea

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

Solution 9 - Intellij Idea

On android studio 4.2 or newer Arctic fox version you will option under appearance & behavior

  1. Windows: file > settings > appearance & behavior > system settings > memory settings
  2. Mac: file > preferences > appearance & behavior > system settings > memory settings

https://i.stack.imgur.com/PEqBK.png

Solution 10 - Intellij Idea

There is a

> idea64.exe

starter in

> IntelliJ IDEA 13.1.5\bin

so you can address more space.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmichaelView Question on Stackoverflow
Solution 1 - Intellij IdeaCrazyCoderView Answer on Stackoverflow
Solution 2 - Intellij IdeaChinView Answer on Stackoverflow
Solution 3 - Intellij IdeaJan NěmecView Answer on Stackoverflow
Solution 4 - Intellij IdeaJimy TenView Answer on Stackoverflow
Solution 5 - Intellij IdeaPeter LView Answer on Stackoverflow
Solution 6 - Intellij IdeaJaisonView Answer on Stackoverflow
Solution 7 - Intellij IdeaNeilView Answer on Stackoverflow
Solution 8 - Intellij IdeaEmre TürkişView Answer on Stackoverflow
Solution 9 - Intellij IdeaMohit GandhiView Answer on Stackoverflow
Solution 10 - Intellij IdeaJulian DehneView Answer on Stackoverflow