31

I am trying to run JUnits from my IntelliJ Idea When I try to run the Test.java file it gives me an error saying that

java: OutOfMemoryError: insufficient memory

I have tried increasing the memory allocated to Idea to as large as 6GB but it still gives me the same error, what am I missing :/

Increasing the following in idea64.vmoptions didn't help. current vmoption settings in /opt/idea/bin are:

-Xms124m
-Xmx2g
-XX:MaxPermSize=2g
-XX:ReservedCodeCacheSize=196m
-XX:+UseCodeCacheFlushing
-ea
-Dsun.io.useCanonCaches=false
-Djava.net.preferIPv4Stack=true

PS:- the project has ~83k files and overall size of project is 1.1 GB

Below Error is encountered:-

Information:Using javac 1.6.0_35 to compile java sources Information:java: The system is out of resources. Information:java: Consult the following stack trace for details. Information:java: at com.sun.tools.javac.util.Position$LineMapImpl.build(Position.java:139) Information:java: at com.sun.tools.javac.util.Position.makeLineMap(Position.java:63) Information:java: at com.sun.tools.javac.parser.Scanner.getLineMap(Scanner.java:1105) Information:java: at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:512) Information:java: at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:550) Information:java: at com.sun.tools.javac.main.JavaCompiler.parseFiles(JavaCompiler.java:804) Information:java: at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:727) Information:java: at com.sun.tools.javac.main.Main.compile(Main.java:353) Information:java: at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:115) Information:java: at org.jetbrains.jps.javac.JavacMain.compile(JavacMain.java:166) Information:java: at org.jetbrains.jps.incremental.java.JavaBuilder.compileJava(JavaBuilder.java:364) Information:java: at org.jetbrains.jps.incremental.java.JavaBuilder.compile(JavaBuilder.java:276) Information:java: at org.jetbrains.jps.incremental.java.JavaBuilder.doBuild(JavaBuilder.java:190) Information:java: at org.jetbrains.jps.incremental.java.JavaBuilder.build(JavaBuilder.java:162) Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.runModuleLevelBuilders(IncProjectBuilder.java:992) Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.runBuildersForChunk(IncProjectBuilder.java:739) Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.buildTargetsChunk(IncProjectBuilder.java:769) Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunkIfAffected(IncProjectBuilder.java:702) Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunks(IncProjectBuilder.java:523) Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.runBuild(IncProjectBuilder.java:314) Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.build(IncProjectBuilder.java:179) Information:java: at org.jetbrains.jps.cmdline.BuildRunner.runBuild(BuildRunner.java:129) Information:java: at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:216) Information:java: at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:111) Information:java: at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler$1.run(BuildMain.java:132) Information:java: at org.jetbrains.jps.service.impl.SharedThreadPoolImpl$1.run(SharedThreadPoolImpl.java:41) Information:java: at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) Information:java: at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) Information:java: at java.util.concurrent.FutureTask.run(FutureTask.java:138) Information:java: at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) Information:java: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) Information:java: at java.lang.Thread.run(Thread.java:662) Information:java: Errors occurred while compiling module 'app' Information:Compilation completed with 1 error and 0 warnings in 3 min 19 sec Information:1 error Information:0 warnings Error:java: OutOfMemoryError: insufficient memory

IDEA COMPILER SETTINGS

5
  • You can use -Xms1g or -Xmx4g BTW 4G = 4096M Commented Jun 20, 2014 at 9:16
  • Think about this, if you called System.exit(0); or your test crashed the JVM, would you want your IDEA to die as well? Commented Jun 20, 2014 at 9:18
  • Could you provide more details for the OutOfMemoryError (is it heap? permgen?), when it happens (after some test run or at the beginning)? Commented Jun 20, 2014 at 23:01
  • @frant.hartm i have attached the error log above Commented Jun 23, 2014 at 3:29
  • Or try this: stackoverflow.com/a/66823924/1507602 Commented Mar 26, 2021 at 20:30

6 Answers 6

67

Based on your log the problem is in compiler heap space.

Go to

Settings -> Compiler -> Build process heap size (MB)

and increase that value.

Sign up to request clarification or add additional context in comments.

7 Comments

tried changing it from 700 to 2000, still didn't work :/
How much physical memory and swap your machine has?
250GB HDD, 8GB RAM, 8.4GB of swap space of which 0.889GB is used up and Intel® Core™2 Quad CPU Q9400 @ 2.66GHz × 4
If you have 88% of your ram allocated it can't allocate additional 2G for the compiler -> hence the error. Freeup some of your ram (reduce what you added to intellij etc...)
This solution helps if your unit test fails during 'Make' and not during the actual execution of the test. Helped me a lot, thanks!
|
35

Idea runs unit tests in a separate java process.

You need to use

Run -> Edit Configurations...

and add your -XmxNNNm to VM Options.

For example:

-ea -Xmx1024m

The "-ea" means "enable assertions".

If your unit test(s) can't run in a 1GB of memory then it's possible that you have a memory leak.

2 Comments

currently the value in VM Options is -ea, what does it mean and what shall i change it to. please explain a bit more
even restarting IDEA after changing vmoptions to -Xmx4024m doesn't help. What do i do?
5

As this OOM happened during compilation, you need to increase compile VM:

Comments

4

In my case, my SpringBootTest configuration has Build (whole project) gradle task in "Before launch". So that's my omission. Eliminating that and issue's gone away.

Or Settings -> Compiler : increase build heap size

Comments

1

To increase heap size is one option. For me (using subversion for source version control) it was even easier to unload some of the modules which I had checked out and where not directly used for the test. This will also speed up the build process for future tests.

Right click on any module in the project-area of IntelliJ -> Load/Unload modudules -> Choose one/some bigger module and move to the "unload" area.

Comments

0

I had a project with big SB and test Containers IT Tests, which were eating a lot of memory. And I was getting OOM Java Heap Space when running all the tests in IntelliJ.

What worked from me:

      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <argLine>-Xms800m -Xmx2048m</argLine>
        </configuration>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.