简体   繁体   中英

IntelliJ Idea giving java.lang.OutOfMemoryError: Java heap space error even after increasing heap size

I have repeatedly got the java.lang.OutOfMemoryError: Java heap space error when compiling my android project on IntelliJ Idea.

I increased my java heap space by following the link here however that didn't solve the problem. The funny thing is, at times my app will compile, and at other times the app will not compile due to the java heap space error. Even when I have made no changes to the app, it will compile at times and fail at times.

Any idea as to how I can solve this problem?

I am compiling an android project, could it be due to the large amount or resources (drawable hdpi, xhdpi, xxhdpi, large-hdpi, large-xhdpi, large-xxhdpi) that I have? But then again, like I said it compiles at times and at times it doesn't. I'm down to making about 10 attempts to compile each time and luckily it will be successful once.

Here is the error:

Internal error: (java.lang.OutOfMemoryError) Java heap space java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOf(Arrays.java:2271) at com.intellij.util.io.UnsyncByteArrayOutputStream.write(UnsyncByteArrayOutputStream.java:52) at com.intellij.util.io.DataOutputStream.write(DataOutputStream.java:34) at java.io.FilterOutputStream.write(FilterOutputStream.java:97) at com.intellij.util.io.IOUtil.writeString(IOUtil.java:63) at org.jet brains.jps.incremental.storage.OneToManyPathsMapping$PathCollectionExternalizer.save(OneToManyPathsMapping.java:87) at org.jetbrains.jps.incremental.storage.OneToManyPathsMapping$PathCollectionExternalizer.save(OneToManyPathsMapping.java:84) at org.jetbrains.jps.incremental.storage.AbstractStateStorage$1.append(AbstractStateStorage.java:103) at com.intellij.util.io.PersistentHashMap.doAppendData(PersistentHashMap.java:371) at com.intellij.util.io.PersistentHashMap.appendData(PersistentHashMap.java:358) at org.jetbrains.jps.incremental.storage.AbstractStateStorage.appendData(AbstractStateStorage.java:101) at org.jetbrains.jps.incremental.storage.OneToManyPathsMapping.appendData(OneToMan yPathsMapping.java:50) at org.jetbrains.jps.incremental.storage.SourceToOutputMappingImpl.appendOutput(SourceToOutputMappingImpl.java:50) at org.jetbrains.jps.builders.impl.BuildOutputConsumerImpl.registerOutputFile(BuildOutputConsumerImpl.java:65) at org.jetbrains.jps.android.AndroidResourceCachingBuilder.runPngCaching(AndroidResourceCachingBuilder.java:126) at org.jetbrains.jps.android.AndroidResourceCachingBuilder.build(AndroidResourceCachingBuilder.java:48) at org.jetbrains.jps.android.AndroidResourceCachingBuilder.build(AndroidResourceCachingBuilder.java:32) at org.jetbrains.jps.incremental.BuildOperations.buildTarget(BuildOperations.java:100) at org.jetbrains.jps.incremental.IncProjectBuilder.r unBuildersForChunk(IncProjectBuilder.java:744) at org.jetbrains.jps.incremental.IncProjectBuilder.buildTargetsChunk(IncProjectBuilder.java:770) at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunkIfAffected(IncProjectBuilder.java:702) at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunks(IncProjectBuilder.java:523) at org.jetbrains.jps.incremental.IncProjectBuilder.runBuild(IncProjectBuilder.java:314) at org.jetbrains.jps.incremental.IncProjectBuilder.build(IncProjectBuilder.java:179) at org.jetbrains.jps.cmdline.BuildRunner.runBuild(BuildRunner.java:129) at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:220) at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:112) at org. jetbrains.jps.cmdline.BuildMain$MyMessageHandler$1.run(BuildMain.java:132) at org.jetbrains.jps.service.impl.SharedThreadPoolImpl$1.run(SharedThreadPoolImpl.java:41) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:166)

Thanks in advance!

转到设置(Mac上的首选项) - >编译器 - > Java编译器 - >最大堆大小(MB),然后增加大小,然后重启IntelliJ

I just had this problem today, and after doubling/quadrupling the heap sizes under File/Settings/Compiler/Java Compiler and .../Compiler/Android Compiler and it still wouldn't compile.

the value that finally fixed my problem was increasing the value called Compiler Process Heap Size (I doubled it but that probably isn't necessary), which can be found under File/Settings/Compiler

this solved the problem for me using Intellij version 12.1.5 (the latest right now)

also I realize that this thread is a bit old...

Intellij provides you with means to edit Application VM Options. Edit Configurations, I think, is what you are after. This setting is located in the top-right corner, or alternatively you can use shift-control-A "Edit configurations" you should see a dialog and one of the fields is VM Options. Here you can set your application-specific settings, ie -Xmx2048m.

In my case the error was appearing following a "Reload Project" from the "Maven" section. It was throwing the OutOfMemoryError in the "Sync" tab of the "Build" window.

In this case, the proper settings to increase is the VM options for importer that you can find in Settings -> Build, Execution, Deployment -> Build Tools -> Maven -> Importing. In my case, it was set to 512m which was too slow for my project with about 50 modules or so.

I increased the heap size and restarted the IntelliJ several times but it did not work out for me ...

I simply went to build menu and clicked on rebuild project and everything was as good as before

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM