Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.jetbrains.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(OneToManyPathsMapping.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.runBuildersForChunk(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!

like image 646
user2608384 Avatar asked Jul 30 '13 17:07

user2608384


People also ask

How do I fix Java heap space error in IntelliJ?

From the main menu, select Help | Change Memory Settings. Set the necessary amount of memory that you want to allocate and click Save and Restart.

How do you deal with Java Lang OutOfMemoryError Java heap space error?

OutOfMemoryError: Java heap space. 1) An easy way to solve OutOfMemoryError in java is to increase the maximum heap size by using JVM options "-Xmx512M", this will immediately solve your OutOfMemoryError.

What is the maximum heap size in IntelliJ?

Limits the maximum memory heap size that the JVM can allocate for running IntelliJ IDEA. The default value depends on the platform. If you are experiencing slowdowns, you may want to increase this value, for example, to set the value to 2048 megabytes, change this option to -Xmx2048m .

What causes Java Lang OutOfMemoryError Java heap space?

lang. OutOfMemoryError exception. Usually, this error is thrown when there is insufficient space to allocate an object in the Java heap. In this case, The garbage collector cannot make space available to accommodate a new object, and the heap cannot be expanded further.


1 Answers

Go to Settings (Preferences on Mac) -> Compiler -> Java Compiler -> Maximum heap size (MB), and increase the size, then restart IntelliJ

like image 150
Adam Johns Avatar answered Oct 02 '22 23:10

Adam Johns