Android allocates application memory and android applications

Source: Internet
Author: User

Android allocates application memory and android applications

In the Android operating mechanism, devices with different resolutions and RAM sizes are allocated different initial running memory. devices with higher resolution certainly require more memory than devices with lower resolution. for details about the allocated quantity, see/system/build on your device. prop file, which has instructions. (The following figure shows the phone number of the LG 720P device with a resolution of 4.7 inch)

<span style="white-space:pre"></span>dalvik.vm.heapstartsize = 8m        dalvik.vm.heapsize = 256m          dalvik.vm.heapgrowthlimit= 70m  
Heapgrowthlimit is the memory limit of a common application. It can be obtained using ActivityManager. getLargeMemoryClass.

Heapstartsize is the initial memory. When the application is used, the memory increases automatically, and the maximum memory is gradually reached.

AndroidManifest. the xml Application tag has an android: largeHeap = "true" attribute. If it is set to true, you can apply for more memory from the device. The default value is false. if this parameter is set to true, the OOM error is still reported when the threshold value is reached. therefore, Google does not recommend this function. As a developer, we should first consider how to reduce the memory usage or reduce the memory usage increment, rather than simply increasing the memory space.

During development, we should optimize the algorithm logic as much as possible to avoid OOM and use officially recommended methods, such as WeakReference and SoftReference commonly used in the past 2.3, And the LruCache class to date,

Good applications should have a reasonable and clear allocation of memory, rather than creating new objects at will, opening pages without closing old pages, or doing a lot of operations such as resource caching. release the memory in a timely manner, and obtain the maximum available memory of the application in advance using the getLargeMemoryClass () method before caching some image resources, so as to reasonably preset the cache size, in order to effectively avoid OOM problems.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.