简体   繁体   中英

OutOfMemoryError: GC overhead limit exceeded api 19

Error:Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded api 19

What now?

This error occures only when I try to run it on a API 19 emulator (as the error text says as well). So okay, I get that appearently my app just recently became to big... Or did it?

I think I don't actually fully understand that error. What does it mean other then I'd need to increase my heap size?

Here comes the next question: Is it bad to increase it? Can I increase it for API 19 only and leave it where it is for others as it works flawlessly on eg API 23?

What can I do if I don't want to increase it? How do I find out what exaclty is making this so big? What can I do in general to keep it small?

So these are a lot of questions, and to keep them good moderators from telling me to post only one question, here it is, the final and all including question: If it is bad to increase the heap size, what do I need to do to avoid getting this error?

Where are you getting this problem?

During compilation or during running your app?

In case of the first, you need to make sure your heap is big during the compile phase. If you are using Gradle, you would add something like this to your script:

dexOptions {
   javaMaxHeapSize "2g"
}

In case of the second - the errors occurs when running your app, you probably need to redesign your app so it consumes less memory. You cannot control the JVM parameters of your user's devices.

EDIT: I don't know why there is a difference between the 2 API levels, but I think it has something to do with the fact that from API level 21 another runtime(ART) is used. Read more about this here: https://developer.android.com/studio/build/multidex.html Compilation phase is probably a bit different because of this, resulting in different memory requirements between the API levels.

As far as I know there is no way to increase the heapsize on a real phone, it is only possible to increase the heapsize in the emulator. The experience I made is that every device has it's own fixed size of heap used by the VM. I had the same problem with some of my app's not running on "older" Android- / API-versions. I used my old Samsung Galaxy S2 which only has 64MB of heap and this cannot be changed.

The final solution for me was to profile my app and to do a lot of redesign to somehow reduce the memory consumption of my app. Fortunately Google already wrote some stuff about this topic and how to approach it. I suggest you start reading Managing Your App's Memory and Investigating Your RAM Usage . There you will find everything to get started with profiling your app's memory consumption.

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