java: OutOfMemoryError: insufficient memory while

2020-03-10 05:45发布

问题:

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

回答1:

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:

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

Go to

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

and increase that value.



回答3:

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



回答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