I’m developing an Android application which is responsible for showing multimedia such as videos and photos to user.
I have a certain activity for a gallery of photos. In my phone where I’m developing the application everything works correctly. Currently I’m testing it in an emulator with a small screen for checking for layout mistakes and I noticed that the gallery activity crashes when scrolling through photographs by throwing an outOfMemoryException
.
My phone where I was developing the application is a Samsung S Advance, which I think is average, not something really powerful, just a phone with normal specs.
Should I be worried about that exception I’m getting in the emulator or is it something that will never happen in real-world conditions?
1
When Android was still a little boy, it’s parents decided to give it each of its applications a memory limit. Seeing how the screens were relatively small phone-screens and the RAM and resolutions were low it made perfect sense to set this to 16MB per app.
What the parents didn’t fully take into account was that the little boy would get bigger. Screens got bigger, resolutions got way bigger and it’s RAM is now so big you could run Windows on it.
Many manufacturers such as Samsung have increased this per-app memory limit to 24MB or 32MB in their ROMs. I’ve seen tablets with per-app memory limits of 96 to 128MB.
You can find out how high the the memory limit on your device is by calling ActivityManager.getMemoryClass
.
In real life, I’ve seen very few devices that have high resolution screens with the kind of low per-app memory limits as the emulator does, so I wouldn’t worry about it too much.
1
With the emulator, you set the amount of memory when you start it up, and usually its defaults I believe are far less than you would normally have on your phone. Even on a regular phone, there are many pitfalls that will cause an outOfMemoryException, e.g. memory leaks (easier than one might think), loading more bitmap data than the resolution / size supports, loading all your images at once, etc.
In general, if you’re getting an outOfMemoryException on an actual phone, it tends to be one of the coding errors mentioned above.