martinseal1987
martinseal1987

Reputation: 2419

how should i avoid out of memory error?

I get the dreaded oom error in android when loading my frame animations, I have all the corresponding images in my hdpi, mdpi, and xhdpi folders but the app will crash after loading each animation a couple of times. My setup is one activity with 4 image buttons each image button takes a user to a different activity with a different animation and I'm letting the android back button take care of going back to the 4 image buttons, this works and each animation is displayed nicely but if I open one, press back and then open another, eventually (after opening each one twice and pressing back to close them) the app crashes with oom, I've searched a lot on this I think my images aren't at fault the biggest anim is 17 slides at 240x408 for mdpi and 1.5x that for hdpi, I'm guessing its something like the garbage collector isn't being called or isn't being called quickly enough but I've read that you shouldn't explicitly call it, also my animations are not in any threads as I read frame animations should be on the ui thread so my question is given the scenario how do I avoid this out of memory error?

Upvotes: 1

Views: 861

Answers (2)

HHK
HHK

Reputation: 5320

Some tips:

  • Check the logcat for GC error messages to find out more about the OOM exception.

  • Make sure all images are recycled properly (call recycle() on Bitmap objects when you don't need them anymore).

  • Use heap profiling to find out if you have unintended object retention (memory leaks).

  • You can give an app more heap by adding android:largeHeap="true" to the <application> tag of of your AndroidManifest.xml. This works in Android 3.0 versions and up. It is ignored on earlier Android versions.

Upvotes: 1

ligi
ligi

Reputation: 39519

sound like a memory leak to me - please read http://android-developers.blogspot.de/2011/03/memory-analysis-for-android.html

Upvotes: 1

Related Questions