Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java heap space

do you have any idea why I could get a 'Exception in thread "main" java.lang.OutOfMemoryError: Java heap space' error when building my android app, even though I added -vmargs -Xmx1024M -Xms512M to the eclipse arguments ? I would like to know what error could I have made that would trigger such an error at build time, as it would appear to me that only a bug in eclipse or maven could produce such an error at build time. I am using run as maven install to build my application (with the maven android eclipse plugin). Run as-> 'maven package' also produces the same build failure, after waiting roughly 1min30. I have a desktop computer with 3GB of memory, and my application isn't nearly that big.

Thanks.

like image 864
John156 Avatar asked Aug 16 '11 09:08

John156


People also ask

What is heap space Java?

Matthew NeSmith / Nov 11, 2020. The Java heap is the area of memory used to store objects instantiated by applications running on the JVM. When the JVM is started, heap memory is created and any objects in the heap can be shared between threads as long as the application is running.

What is Java heap space out of memory?

Java Heap space is one of the most common errors when it comes to memory handling in the Java Virtual Machine world. This error means that you tried to keep too much data on the heap of the JVM process and there is not enough memory to create new objects, and that the garbage collector can't collect enough garbage.

How do I free up heap space?

The heap is cleared by the garbage collector whenever it feels like it. You can ask it to run (with System. gc() ) but it is not guaranteed to run.


1 Answers

Add -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/some/path to your jvm args so that when it runs out of memory it will dump out the heap. You can then use Eclipse Memory Analyser or jhat to browse the heap and diagnose where the problem might be.

Update: Try increasing the memory of your maven android plugin. In your pom.xml, add a JVM argument for Xmx to the plugin configuration:

<plugin>
  <artifactId>maven-android-plugin</artifactId>
  <configuration>
    <jvmArguments>
      <argument>-Xmx1500m</argument>
    </jvmArguments>
  </configuration>
</plugin>
like image 172
dogbane Avatar answered Oct 25 '22 04:10

dogbane