java:OutOfMemoryError:在Idea中运行JUnits时内存不足

2022-09-02 14:21:13

我正在尝试从我的IntelliJ Idea运行JUnits当我尝试运行测试.java文件时,它会给我一个错误,说

java: OutOfMemoryError: 内存不足

我已经尝试将分配给Idea的内存增加到6GB,但它仍然给我同样的错误,我错过了什么:/

idea64.vmoptions中增加以下内容没有帮助。/opt/idea/bin 中的当前 vmoption 设置包括:

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

PS:- 该项目有~83k文件,项目总大小为1.1 GB

遇到以下错误:-

信息:使用 javac 1.6.0_35 编译 java 源 信息:java:系统资源不足。信息:java:有关详细信息,请参阅以下堆栈跟踪。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: atcom.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.compile(Main.java:353) Information:java: at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:115) Information:java: at org.jetbrains.jps.javacMain.compile(JavacMain.java:166) Information:java: atorg.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: atorg.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: atorg.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 happen编译模块“app”时 信息:编译完成,3 分 19 秒内出现 1 个错误和 0 个警告 信息:1 错误 信息:0警告错误:java: 内存不足错误: 内存不足

IDEA COMPILER SETTINGS


答案 1

根据您的日志,问题出在编译器堆空间中。

转到(G)

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

并增加该值。


答案 2

Idea在单独的java进程中运行单元测试。

您需要使用

Run -> Edit Configurations...

,然后添加到虚拟机选项。-XmxNNNm

例如:

-ea -Xmx1024m

“-ea”表示“启用断言”。

如果您的单元测试无法在1GB内存中运行,则可能是内存泄漏。


推荐