137

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?

cdeszaq
  • 30,869
  • 25
  • 117
  • 173
michael
  • 106,540
  • 116
  • 246
  • 346

11 Answers11

218

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.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • 18
    And a restart is required afterwards :) – cgl Apr 16 '13 at 16:23
  • 13
    I know this is slightly off-topic but might save someone some hair if they come across this. I was having the same problem, but mine stemmed from when I was doing a `mvn install` in IntelliJ. The solution was to modify the `Settings | Maven | Runner | **VM Options**` I must have tried every other setting in there till I got that one right. Hope it helps someone. – FuriousGeorge Sep 26 '13 at 19:54
  • 2
    I can find it till ` Maximum heap size` Do i have to add it as a additional command line parameter? – clankill3r Apr 24 '14 at 12:51
  • 14
    @clankill3r try `Settings` | `Compiler` | `Build process heap size`. – CrazyCoder Apr 24 '14 at 13:05
  • 7
    For more recent versions of Intellij (mine is 2016.1.3) this parameter is called "Build process heap size (Mbytes)" and can be found in "Settings | Build, Execution, Deployment | Compiler". – tomger Jun 13 '16 at 09:17
  • I was able to find it under Settings (Preferences on Mac) | Build, Execution, Deployment | Compiler | ActionScript & Flex Compiler --> Compiler heap size Intellij Ultimate Edition 2018 – akshay Oct 17 '19 at 18:48
114

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

enter image description here

Chin
  • 19,717
  • 37
  • 107
  • 164
6

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

Jan Němec
  • 309
  • 6
  • 14
6

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

Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
Jimy Ten
  • 57
  • 1
  • 3
  • Why did you [edit](https://stackoverflow.com/posts/51455242/revisions) out that link? Are you afraid of what happened [here](https://stackoverflow.com/a/50187283/4751173)? – Glorfindel Jul 21 '18 at 10:52
  • i have given correct answer and i have given credit to another website but still i can see two downvotes to my answer.and answer which i have given is practically correct which i have faced and resolved it. – Jimy Ten Jul 21 '18 at 10:53
  • please let me know if i can give credit to another website. – Jimy Ten Jul 21 '18 at 10:56
  • 2
    That temporary downvote was from me. If you want to give credit, please link to the exact page where you found the information, not a list of tutorials. – Frenzy Li Jul 21 '18 at 10:57
4

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.

Peter L
  • 2,921
  • 1
  • 29
  • 31
4

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

Jaison
  • 715
  • 1
  • 10
  • 33
1

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.

Neil
  • 7,482
  • 6
  • 50
  • 56
1

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

0

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

Emre Türkiş
  • 992
  • 9
  • 23
0

Link for IntelliJ documentation on setting custom parameters

I was able to set the JVM options by going to the Run Debug configurations and setting the below value.

enter image description here

Nirojan Selvanathan
  • 10,066
  • 5
  • 61
  • 82
-3

There is a

idea64.exe

starter in

IntelliJ IDEA 13.1.5\bin

so you can address more space.

Julian Dehne
  • 83
  • 1
  • 3
  • This answer is to some extent correct, although is not in the context of question above. idea64.exe does give you more permgen memory, use idea64.exe if you're on 64bit OS. Found it useful coz 32bit idea.exe was crashing when running out of mem during build. – Adil H. Raza Apr 18 '17 at 16:24