Android heap size on different phones/devices and OS versions
Asked Answered
G

7

74

Does anyone know if the heap size on Android phones is a constant value according to what is set in the OS version or if this is a setting which the phone producers can decide on?

Is the heap size proportional to the amount of RAM on the phone?

I've only found articles where people say that the heap size of an application is 16M. However, these articles are a bit old. From what I see, as an example, heap sizes vary from around 20M up to 24M on one specific model. This phone has 768M of RAM.

Gerlach answered 18/3, 2011 at 10:7 Comment(1)
if der is 30mb total heap to app. and if only 7 mb is alloted and remaining is free, can reaming memory be used by other apps?Exciseman
H
52

Does anyone know if the heap size on Android phones is a constant value according to what is set in the OS version or if this is a setting which the phone producers can decide on?

Technically, it is a setting which the phone producers can decide on. Android is open source. I do not recall the Compatibility Definition Document spelling out heap size requirements, though I haven't looked recently.

Is the heap size proportional to the amount of RAM on the phone?

No, 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.

I've only found articles where people say that the heap size of an application is 16M.

Searching StackOverflow on [android] "heap size" turns up this answer.

Hallow answered 18/3, 2011 at 13:16 Comment(1)
Yes, I saw that answer too. I was just wondering if there were any guidelines to this, and if the RAM has anything to do with it. I guess we'll just have to hope that manufacturers abide by Google guidelines. Thanks for your input. I was asking this because I saw an increase in OutOfMemory issues for a specific phone.Gerlach
D
125

Some more device info extracted from build.prop files (adb -d pull /system/build.prop):

Phones (Android Version):

  • HTC Wildfire (2.2.1) = 16MB
  • HTC Wildfire S (2.3.5) = 20MB
  • HTC Salsa (2.3.3) = 20MB
  • HTC Desire (2.3.3) = 32MB
  • HTC Desire S (2.3.5) = 32MB
  • Sprd - Richview - S111 (2.3.5) = 32MB
  • Samsung Galaxy S GT-I9000 (2.2) = 48MB
  • Samsung Galaxy R GT-I9103 (2.3.5) = 64MB
  • Samsung Galaxy Y GT-S5360 (2.3.5) = 64MB
  • Samsung Galaxy Note N7000 (4.1.2) = heapstartsize=8m, heapgrowthlimit=64m, heapsize=256m
  • Samsung Galaxy S3 GT-I9300 (4.3, xhpdi) = 8/64/256MB
  • Samsung Galaxy S4 GT-I9505 (4.4, xxhpdi) = 8/128/512MB
  • Google Galaxy Nexus (4.3) = 8/96/256MB
  • Google Nexus 4 (4.4, xhdpi) = 8/192/512MB
  • Google Nexus 5 (4.4, xxhdpi) = 8/192/512MB
  • Samsung Galaxy S6 SM-G920W8 (7.0) = 8/256/512MB

Tablets (Android Version):

  • Samsung Galaxy Tab GT-P1000 (2.2) = 48MB
  • Samsung Galaxy Tab 8.9 GT-P7300 (3.2) = 5/64/288MB
  • Samsung Galaxy Tab 10.1 GT-P7500 (3.2) = 5/64/288MB
  • Samsung Galaxy Tab 3 10.1 GT-P5200 (4.2, mdpi) = 8/96/256MB
  • Acer Iconia A500 (3.2.1) = 5/48/256MB
  • Kindle Fire HD 7" (4.0.3) = 5/48/256MB
  • Asus Transformer Prime TF201 (4.1.1) = 5/48/256MB
  • Nexus 10 (4.4.3) 16/192/512 MB
Dix answered 30/3, 2012 at 9:34 Comment(4)
Worth noting that the manifest application attribute android:largeHeap="true" appears to increase the available heap space from the "heapgrowthlimit" value to the "heapsize" value. This will vary by device, though.Sib
From a post in xdadeveloper by h2g2: heapstartsize is the size of a new Dalvik VM heap when initialized. heapgrowthlimit is the size limit for normal Dalvik VM heaps. heapsize is the size limit for Android apps that specify android:largeHeap=true in their application manifest.Aleris
in "Google Galaxy Nexus (4.3) = 8/96/256MB", why there are multiple heap size? 8? 96? 256?Jocular
Those values are heapstartsize, heapgrowthlimit, heapsize. See jeffmixon.com/… for more info.Dix
H
52

Does anyone know if the heap size on Android phones is a constant value according to what is set in the OS version or if this is a setting which the phone producers can decide on?

Technically, it is a setting which the phone producers can decide on. Android is open source. I do not recall the Compatibility Definition Document spelling out heap size requirements, though I haven't looked recently.

Is the heap size proportional to the amount of RAM on the phone?

No, 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.

I've only found articles where people say that the heap size of an application is 16M.

Searching StackOverflow on [android] "heap size" turns up this answer.

Hallow answered 18/3, 2011 at 13:16 Comment(1)
Yes, I saw that answer too. I was just wondering if there were any guidelines to this, and if the RAM has anything to do with it. I guess we'll just have to hope that manufacturers abide by Google guidelines. Thanks for your input. I was asking this because I saw an increase in OutOfMemory issues for a specific phone.Gerlach
C
21

Not only phone producers, but anyone who creates a version of the Android OS, can specify the maximum allowed heap size, based upon the specific requirements of their devices. Some Android roots, such as CyanogenMod, even allow the user to select the heap size herself as a setting.

You can detect the maximum allowed heap size using the method

Runtime.getRuntime().maxMemory();

Additional information on this topic is available here.

If your app normally needs more than 16MB of heap, a suggested approach would be to set a minimum OS version level in your manifest that ensures that the overwhelming majority of those downloading your app will have at least the amount that you need, and then find a way to degrade your functionality gracefully in a way that reduces your heap requirements as needed, down to a base level of 16MB, for the small number of users with less than your optimal amount of heap who fall through that sieve.

Here are some figures showing the association of phone RAM with OS version (based on current, not original, OS). I believe that a phone having at least 1GB of RAM will almost always have more than 16MB of heap. Note that the percentages here are for the number of phone models supporting the indicated memory, not total phones in use, which may be quite skewed toward certain models. These numbers were obtained by plugging inputs into the following phone finder (which includes 1500 Android phone models) and so are only ballpark figures: http://www.gsmarena.com/search.php3

Percentage of phone models having at least 1GB of RAM, by current OS version (not version at launch):

Phones running         Percent of models having at least 1GB of RAM   Percentage of all models
4.4 and up             100 percent                                    1.5
4.3 and up             100 percent                                    2.9
4.2.x and up           74 percent                                     18.7
4.1.x and up           71 percent                                     37
4.0 and up             62 percent                                     60
2.3.x and up           57 percent                                     71
2.2 and up             44 percent                                     93
2.1 and up             44 percent                                     97
ALL OS VERSIONS:       41.5 percent                                   100
Chishima answered 9/5, 2012 at 10:3 Comment(2)
How would a minimum OS level help? Even KitKat 4.4 is now getting optimized for low-RAM devices.Cockeyed
@NoBugs: Unfortunately, the Google Play store does not presently provide a way to filter which devices can see your app based on heap size, so less precise criteria must be used in an attempt to attain that effect for most users. In general, later OS versions will be on devices with larger heap sizes. So specifying a higher version should result in most devices having more available heap. When exceptions to that rule are encountered, the app should degrade gracefully.Chishima
C
11

You should be able to check the max vm heapsize using:

getprop dalvik.vm.heapsize

at Android terminal (connectbot or adb shell etc). It is possible to remount read-write and set the heap size in the build.prop file as well. (Make sure you have recovery installed so you can re-set it if you accidentally make it too small, it won't boot up).

Cockeyed answered 22/5, 2012 at 5:26 Comment(0)
S
9

The "VM Budget" that an application is allowed to use varies from device to device. Tablets typically permit a larger budget than phones.

Here are some VM budget sizes I've found for various devices.

  • G1 = 16 Mb
  • Droid = 24 Mb
  • Nexus One = 32 Mb
  • Xoom = 48 Mb
  • GalaxyTab = 64 Mb.

(Note: if you've found differently, let me know)

Stratigraphy answered 19/8, 2011 at 19:37 Comment(1)
HTC Desire (v 2.3.3) = 32MB Samsung Galaxy R GT-I9103 (v 2.3.5)= 64MBDix
P
9

There is actually a defined minimum application memory that depends on the screen size and density:

Mobile devices typically have constrained system resources. Android devices can have as little as 16MB of memory available to a single application. The Android Compatibility Definition Document (CDD), Section 3.7. Virtual Machine Compatibility gives the required minimum application memory for various screen sizes and densities. Applications should be optimized to perform under this minimum memory limit. However, keep in mind many devices are configured with higher limits.

Quoted from: http://developer.android.com/training/displaying-bitmaps/index.html

But as others have stated, each device manufacturer decide the actual value for the device, so it could be greater than this (but not smaller).

The mentioned Compatibility Definition Document (CDD) listing the minimum requirements for each version of android: https://source.android.com/compatibility/cdd.html

For the latest version of Android there is a html verison available, and we can directly link to the runtime memory section there: https://source.android.com/compatibility/android-cdd.html#3_7_runtime_compatibility

For Android 2.3:

Device implementations with screens classified as medium- or low-density MUST configure Dalvik to allocate at least 16MB of memory to each application. Device implementations with screens classified as high-density or extra-high-density MUST configure Dalvik to allocate at least 24MB of memory to each application. Note that device implementations MAY allocate more memory than these figures.

For the modern versions, there is instead a table where it depends on screen density etc:

For Android 4.2, example row from that table:

small / normal / large size and xhdpi density: 64MB

For Android 6, extract:

small/normal xhdpi: 80MB

small/normal xxhdpi: 128MB

small/normal xxxhdpi: 256MB

There is a table for the other Android 2.x, 4.x, 5.x and 6 versions too in those documents (see CDD link above).

Refer to this google link to easily find screen densities etc for specific devices: https://design.google.com/devices/

Pindling answered 19/4, 2013 at 19:12 Comment(9)
what about other versions of android, between 2.3 and 4.2 ?Lining
Updated the answer mentioning that there is such a table listing for all Android 4.x versions. Not the earlier versions though.Pindling
i don't understand. do you mean that for versions 3.0 to 4.1 , there is no description of the heap requirements?Lining
In the linked documents in the answer (one for each version of the platform) there is a table as described for all 4.x versions (4.0, 4.1 and 4.2 currently) Meaning for all the versions 4.x (4 dot something) there is such a table.Pindling
ok, i still don't understand. can you please update your answer to include how much minimal heap size each version (or versions range) has ?Lining
Updated answer to make this clear: There is a table where the minimum depends on pixel density etc. So not one single heap size for each version. You will have to check the document (CDD linked in the answer) and just look at the table (search for "heap") for each versionPindling
searching for "heap" on all of the CDD files didn't result in anything related to the heap size. however, i think that searching for "Virtual Machine Compatibility" will work. also, searching for "Memory and Storage" would result in the total device memory requirements.Lining
i wonder though what is going on with the missing android versions like 3.x and what's between the versions.Lining
since i had a similar question, i've decided to answer it with all of the numbers i've found: https://mcmap.net/q/27131/-is-there-a-minimal-heap-size-for-android-versions . since it's not a full answer (no idea if there is a requirement for the large-heap flag) , i haven't marked it as answered.Lining
R
0

This data is working for me. Select Emulator Tablet Android TV RAM 1536MB VM HEAP 16MB Internal Storage 800MB Studio -managed 100

Rubinstein answered 6/7, 2016 at 14:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.