问题
Many posts have talked about Android heap size, and so far what I've found out is that the only common thing about max heap size is that it's at least 16MB, but that was the limit ever since API 3. For using more memory, people would suggest to use the NDK or anything that is beyond the "normal" Android development.
Is there any Android version that has a requirement from the devices to have a larger heap size, so that I could start assuming a larger one and stop being so cheap on memory?
Is there also a requirement about the flag of the large heap (from API 11 - honeycomb) inside the manifest, or is it a vague request that the device might even ignore it?
It's just that the Android hardware has improved so much over the years, yet we still need to be so cheap on memory even though devices now have more than 1GB of ram. And it's weird that we can't ask from the OS to get us a specific amount of heap size and promise it that we won't use any more of this.
回答1:
ok, i've finally found the answer (thanks to this post) :
the bare minimal for all versions of android (including 5) , is 16MB.
the requirements for each of the android versions can be read about here:
http://source.android.com/compatibility/downloads.html
you can read about them by opening the CDD files and searching for "Runtime Compatibility" (or "Virtual Machine Compatibility" for old versions). also, you can find the minimal RAM requirement by searching for "Memory and Storage", but i think it's only the requirement for the system itself.
so, for example, on 4.0.3 - 5 the minimal heap size is:
- 16MB: small/normal with ldpi/mdpi, or large with ldpi
- 32MB: small/normal with tvhdpi/hdpi, or large with mdpi
- 64MB: small/normal with xhdpi, or large with tvdpi/hdpi, or xlarge with mdpi.
- 96MB: small/normal with 400dpi, or xlarge with tvhdpi/hdpi
- 128MB: small/normal with xxhdpi, or large with xhdpi
- 192MB: small/normal with 560dpi, or large with 400dpi, or xlarge with xhdpi .
- 256MB: small/normal with xxxhdpi, or large with xxhdpi
- 288MB: xlarge with 400dpi
- 384MB: large with 560dpi, or xlarge with xxhdpi
- 512MB: large with xxxhdpi
- 576MB: xlarge with 560dpi
- 768MB: xlarge with xxxhdpi
I can't find the minimal heap size for versions 3.x but it's probably the same as 4.0.3 .
for 2.1 - 2.3 , the minimal heap size is :
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.
meaning:
- medium screen or ldpi - 16MB
- hdpi or xhdpi - 24MB
i can't find the minimal heap size for version 1.6 , but it's probably the same as 2.1 .
also, i can't find out what should the large-heap flag do for each of the android versions (since 3.0) .
来源:https://stackoverflow.com/questions/14375947/is-there-a-minimal-heap-size-for-android-versions