How to view the maximum memory and memory usage that a program can use

Source: Internet
Author: User

When loading a list with a large number of images, usually we have to consider that when the image reaches a certain limit, the lack of memory causes the program to crash due to oom. The next step may be to find a picture to load the open source framework for once and for all. Oom not urgent to solve, first to understand the program available memory of a lost knowledge. In the face of Oom, have you ever thought about this:

1. What is Oom

Oom is known to be out of memory of the abbreviation that is an overflow, popular point is that memory ran out.

2. Why is Oom

Memory usage exceeding the upper limit causes a memory overflow. For example, memory leaks, when the program is running during the dynamic application of memory space is no longer used but not released in a timely manner, resulting in application memory continues to grow, until the memory limit is exceeded to cause the program to end.

3. How to view the memory limit? is the maximum memory size available for each application consistent? How do I see the memory usage of the currently running app?

These are the questions to be explained next. is to understand the beginning of memory usage.


"We all know that Android is a multi-tasking operating system, running many programs, we need to allocate memory, It is not possible to allocate more and more memory to a program so that the entire system crashes, so the size of the heap has a hard limit, related to the device, from the development is also more and more large, G1:16mb,droid:24mb,nexus ONE:32MB,XOOM:48MB, But once the scope of this use is exceeded, Oom generates " 

A similar description is readily visible in many memory-related blogs. So here's the question,


How is the memory size allocated by the one program viewed?

1. first to understand the three genera of the Dalvik heap configuration :

    • Dalvik.vm.heapstartsize=8m: Represents the initial size that the system assigns to an application when it is started.
    • DALVIK.VM.HEAPGROWTHLIMIT=64M: The maximum available memory, or memory threshold, that a single application is allocated. When the application's memory usage exceeds this threshold, it causes oom.
    • dalvik.vm.heapsize=256m: The maximum amount of memory that a single virtual machine can allocate. (Each application is run in a single virtual appliance, in order to avoid a single process crash that causes the entire system to crash) the maximum available memory for a single application is Heapgrowlimit, and if you want to request larger memory, You can specify Android:largeheap as true in the application tag of manifest.xml so that the DVM heap can reach heapsize maximum, but if memory usage also exceeds that value, it can also cause oom to occur.

A more comprehensive description of these properties steps: Android Dalvik heap analysis and Android memory management &memory Leak & OOM Analysis


2. The program can use the maximum memory view method

Next look at the two ways to view/get Heapgrowthlimit and HeapSize values:

The first is to open the System/build.prop file in your phone with the file Manager, where you can configure some of the properties of the Dalvik virtual machine:




Look at the familiar words in the red box is not feeling very cordial. This file is editable. It is also possible to know from here that these values can be different from one device to another. "Manufacturers will appropriately modify the/system/build.prop file to increase this value for the configuration of the device."


The second method can obtain the memory threshold value by code:

        Activitymanager manager = (Activitymanager) getsystemservice (context.activity_service);        Available heap memory, the maximum memory that a single application can use, and if the application memory usage exceeds this value, the oom        int heapgrowthlimit = Manager.getmemoryclass () is reported;        The maximum value of the process memory space allocation, which represents the maximum memory available for a single virtual machine,        int heapsize = Manager.getlargememoryclass ();        L.D ("Heapgrowthlimit =" +heapgrowthlimit+ "M" + ", heapsize =" +heapsize+ "");


Once you understand the true face of an application's maximum memory usage, take a look at:

Second, how to check the usage of runtime memory?
You can use the Memory monitoring tool heap provided in DDMS to monitor memory changes for a process:



Select the currently running program's process in the left panel and click on the "Update Heap" icon, then the right panel will show the memory usage of the current process.

    • Heap Size: The size of heap memory occupied by the current application (Heap Size = allocated +free)
    • Allocated: Indicates the memory size occupied by the current active object
    • Free: Indicates how much memory the system freed through GC operations
    • % used: current memory usage ratio (= Allocated/heap Size)

In the previous issue of implementing a simplest picture list, a list of images was implemented , and when we kept sliding the list to load the image, we observed in DDMS that the size of the heap was not kept in a reasonable range, but continued to rise, When the maximum memory usage limit is reached, such as 64m, the program appears oom.
The changes of these parameters can be observed by the pro-test procedure.


Reference:

Android Best performance Practice (ii)--Analyze memory usage

An analysis of Android Dalvik Heap

Android Memory Management &memory Leak & OOM Analysis

What's the largeheap in manifest?

Android oom-Resize Heap



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

How to view the maximum memory and memory usage that a program can use

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.