Android Memory Monitor Tool DDMS--Heap

Source: Internet
Author: User

First, what is a memory leak
A memory leak is a memory that is dynamically allocated in the middle of the program, but does not release the memory at the end of the program, causing that portion of memory to be unavailable. Causes the system to run slower or the application crashes.
Second, how to detect memory leaks in Android
The DDMS in Android tools comes with a very good memory monitoring tool heap, which detects memory changes in a process, which we can roughly test to see if there is a leak in an application.
Third, the specific operation
1. Open Eclipse, switch to DDMS, and confirm that the devices view and the heap view are open;
2, the phone through the USB link to the computer, link, select the "USB debugging" mode;
3. After the link is successful, the serial number of the mobile device will be displayed in the Devices view of the DDMS, along with the part of the process information that is running on the device.
4. In devices, click the program you want to monitor.
5. Click "Update Heap" in the top row of icons in the Devices view interface
6. Click the heap View
7. Click the "Cause GC" button in the heap view.
8. The process that needs to be detected can be monitored. Such as:

Iv. how to determine memory leaks
In the middle of the heap view, there is a type called data object, which is an object of the class type that exists in our program. In the data object row, there is a column "total size", whose value is the amount of memory for all Java data Objects in the current process, in general, the size of this value determines whether there is a memory leak. It can be judged as follows:
1. Enter an application, continue to operate the application, while observing the total size value of the data object
2. Under normal circumstances, the total size value will stabilize within a limited range.
3. Conversely, if an object reference is not released in the code, the total size value of the data object does not come down significantly after each GC, and as the number of operations is increased, the value of total size is increased until an upper limit is reached, causing the process to be killed.

In our program, if there is an increasing phenomenon in a process, there may be a problem with the application leaking. If a process crashes during an operation, the application may have requested no space and there may be a memory leak.

Android Memory Monitor Tool DDMS--Heap

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.