4

I was reading about OutOfMemory error in Android, which comes when Android runs out of memory. Do we know that if my app consumes some x MB of memory then it will give OutOfMemory error? Does Android allocates a specific amount of memory to each app depending on the device and total physical memory?

For example, I've a device with 2GB RAM installed, 500MB is taken by OS, 500 MB is taken by other apps. Now my app has 1048MB of memory to run. So in this particular case when the system gives OutOfMemory?

Jainendra
  • 24,713
  • 30
  • 122
  • 169
  • 1
    That´s a really good question. I have sometimes Exception reported by Google about out of memory on my apps (only two or three apps). But I have no idea why, I got no heavyweight UI or other work there. And the important question is: How to handle this...? – Opiatefuchs May 06 '15 at 06:28
  • http://stackoverflow.com/questions/30068676/how-to-prevent-reloading-of-images-in-listview-with-custom-adapter-when-refresh/30068976#30068976 – Yogendra May 06 '15 at 06:28
  • @Yogandra.....very interesting. Sometimes I wonder why I miss such things.... – Opiatefuchs May 06 '15 at 06:30

3 Answers3

1

Each app has some memory limit it can utilize for heap allocations. It differs for different phones (and you can increase it in manifest as well). This answer provides a great detail on this, giving specific figures for some models and settings.

As for how it is determined:

it tends to be based more on screen resolution, as higher-resolution screens tend to want to manipulate larger bitmaps, so Google makes heap size recommendations that, hopefully, device manufacturers will abide by. CommonsWare

Community
  • 1
  • 1
AndroidEx
  • 15,524
  • 9
  • 54
  • 50
0

What you are looking for is best described by google itself Here


To get how much memory you can use you could do this:

ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
int memoryClass = manager.getMemoryClass();
Log.v("onCreate", "memoryClass:" + Integer.toString(memoryClass));
Sid
  • 14,176
  • 7
  • 40
  • 48
0

your OutOfMemory Exception caused by Heap size , not about the RAM .

To maintain a functional multi-tasking environment, Android sets a hard limit on the heap size for each app. The exact heap size limit varies between devices based on how much RAM the device has available overall. If your app has reached the heap capacity and tries to allocate more memory, it will receive an OutOfMemoryError.

here an useful link : https://developer.android.com/training/articles/memory.html

hope that help you :)

Linh Nguyen
  • 1,264
  • 1
  • 10
  • 22