Settings of the android heap memory

Source: Internet
Author: User

 

We all know that the upper-layer applications of Android are based on Dalvik virtual machine. The Dalvik VM is characterized by registers. Compared with Sun's JVM (based on stacks, there are no registers), theoretically there are fewer instructions to complete the same function, but the instruction set is complex. In android2.2, Dalvik has finally implemented the JIT (Just In Time) function, making a huge step forward.

 

We recently encountered an outofmemory error, usually caused by heap memory overflow. Some posts on the Internet say that you can use the function to set the heap size of the application to solve this problem.

 

 

Vmruntime. getruntime (). setminimumheapsize (newsize );

 

Heap is the most memory-consuming part of the VM, which is usually dynamically allocated. The heap size is not static. Usually there is a allocation mechanism to control its size. For example, the initial heap size is 4 MB. When the space of 4 MB is occupied by more than 75%, the allocated heap size is 8 Mb. When the space of 8 Mb is occupied by more than 75%, the allocated heap size is 16 Mb. In turn, when the 16 m heap uses less than 30%, the size of the 16 m heap is reduced to 8 m. Resetting the heap size, especially compression, usually involves copying the memory. Therefore, changing the heap size has a negative impact on the efficiency.

 

The preceding example shows three parameters: Max heap size, Min heap size, and heap utilization ).

 

Max heap size is the upper limit of heap memory. The default value of Android is 16 MB (24 MB for some models), which cannot be changed for common applications. The setminimumheapsize function only changes the lower limit of the heap, which can prevent too frequent heap memory allocation. When the minimum heap memory size is set to exceed the upper limit, the upper limit of the heap is still used, it has no effect on insufficient memory.

 

Settargetheaputilization (float newtarget) can be used to set the percentage of memory utilization. When the actual percentage of utilization deviates from this percentage, the virtual opportunity is used to adjust the heap memory size during GC, bring the actual usage closer to the percentage.

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.