0

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?

Martijn Pieters
  • 14,499
  • 10
  • 57
  • 58
libathos
  • 103
  • 3
  • If you're using the emulator packaged with the SDK, check that the [AVD](http://developer.android.com/tools/devices/index.html) you're using has sufficient memory. And yes, any exception that can be thrown by anything you do is something you should either be prepared for or willing to let make your application crash. – Blrfl Feb 25 '14 at 11:31

2 Answers2

0

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.

Menno
  • 116
  • 2
  • I checked it out, and the emulator has indeed 16MB ram per app,My phone though assigns 64MB is this too much? I mean should I check what happens for devices that assign 32MB and 24 MB? – libathos Feb 26 '14 at 14:26
0

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.

NameSpace
  • 101
  • 2