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.
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.
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.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With