Reputation: 329
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?
Upvotes: 0
Views: 6855
Reputation: 13541
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.
Upvotes: 1