0

I have an app that animates gif's by loading all of the frames as separate bitmaps into memory and having a thread loop through them assigning them to the imageViews.

The imageViews are on fragments and the fragments are loaded on a pageViewer. I've set the offscreen limit of the pageviewer to 1 so at most I'm dealing with three fragments/gifs at a time.

Now on the emulator with 2.1 I get this error if all three gifs are in memory at the same time:

11-25 17:28:34.269: E/dalvikvm-heap(524): 292000-byte external allocation too large for this process.
11-25 17:28:34.269: E/(524): VM won't let us allocate 292000 bytes

I get the same error on 2.3.3 but not on 4.0.3 emulator or my galaxy tab 10.1 running 4.0.4 - those two run fine and considerably faster.

I've tried loading a 1024x999 3.2MB gif and even the 4.0.3 emulator failed but my tablet still managed to show a number of gifs until it too stopped loading them; the app used about 250-300MB of RAM.

So is there a way to predict how real devices will work? Should I target higher API versions?

tshepang
  • 10,772
  • 21
  • 84
  • 127
Arnas
  • 199
  • 3
  • 14
  • Are the gifs loaded from the web, or are they provided by you? If they're resources, you should use an Animation instead. This was asked recently: http://stackoverflow.com/questions/12977039/android-loading-images-with-a-delay/12978091#12978091 – dmon Nov 26 '12 at 18:35
  • Also note that the per-app limit is much smaller than the memory of the device. – dmon Nov 26 '12 at 18:37
  • "the app used about 250-300MB of RAM." That is way too much. http://stackoverflow.com/questions/2630158/detect-application-heap-size-in-android Some devices don't even have 250MB in total – zapl Nov 26 '12 at 18:38
  • the gifs are downloaded, also the 250-300MB usage was an edge case. – Arnas Nov 26 '12 at 19:12

1 Answers1

1

You have to be very careful when loading so many Bitmaps. You can EASILY exceed how much memory you need. Remember, you are on a limited device, DON'T expect unlimited resources try to be as memory efficient as you possibly can.

You can very likely solve your problem if you learn about best practices from the android dev site:

http://developer.android.com/training/displaying-bitmaps/load-bitmap.html

Give it a read, should help you solve your problem.

JoxTraex
  • 13,105
  • 5
  • 30
  • 45
  • there's definitely some ways that i could curb memory usage and i plan to do so, but what concerns me is the lack of consistency. I spent some time trying to destroy the gif's once the user goes to next fragment since i assumed that i was over the app memory limit and then i tried it on my real device and saw that it was not needed and the app limit is somehow not triggered. – Arnas Nov 26 '12 at 19:16