What is the maximum amount of RAM an app can use?

What is the maximum amount of memory (in Megabytes / as percentage of the total RAM) that an Android application (that is not a system app) can use?

That varies by device. getMemoryClass() on ActivityManager will give you the value for the device your code is running upon.

Are there any differences between the Android versions?

Yes, insofar as OS requirements have increased over the years, and devices have to adjust to match.

Are there differences concerning the manufacturer of the device?

Yes, insofar as manufacturers manufacture devices, and the size varies by device.

Which “side factors” are taken into consideration when it comes to determining how much RAM an app can use?

I have no idea what “side factors” means.

Early devices had a per-app cap of 16MB; Later devices increased that to 24MB or 32MB

That’s about right. Screen resolution is a significant determinant, as larger resolutions mean larger bitmaps, and so tablets and high-resolution phones will tend to have higher values yet. For example, you will see devices with 48MB heaps, and I wouldn’t be surprised if there are values higher than that.

How is it possible that apps exceed that limit?

You assume that the author of that app knows what (s)he is doing. Considering that memory usage of an app is difficult for a core Android engineer to determine, I would not assume that the app in question is necessarily providing particularly accurate results.

That being said, native code (NDK) is not subject to the heap limit. And, since Android 3.0, apps can request a “large heap”, usually in the hundreds of MB range, but that’s considered poor form for most apps.

Furthermore, I noticed that some apps of mine crash with an OutOfMemoryException when using around 30-40 Megabytes.

Bear in mind that the Android garbage collector is not a compacting garbage collector. The exception really should be CouldNotFindSufficientlyLargeBlockOfMemoryException, but that was probably deemed too wordy. OutOfMemoryException means that you could not allocate your requested block, not that you have exhausted your heap entirely.

Leave a Comment