Android App Memory Leak Debug Tool (1)

Source: Internet
Author: User



Android App Memory Leak tool (1) Use Memory Monitor tool ddms–> Heap

Operation Steps

  1. After you start eclipse, switch to the DDMS perspective and make sure that the devices view, the heap view, are open, and that you do not open the direct window>showview>

  2. Link your phone to your computer via USB and confirm that your phone is in "USB Debug" mode

  3. After the link is successful, the serial number of the mobile device and the part of the process information that is running on the device will be displayed in the Devices view of the DDMS.

  4. Click to select the process you want to monitor, if you don't see your process in the list of processes, select one of the tools that let device row is available, and then click the Update Heap to automatically find the process of our running application, such as the two application process of pony running;

  5. Click the "Cause GC" button in the heap view;

  6. After clicking on the cause GC, we can see the memory of our application as follows:

Description

1 Click the Cause GC button to request a GC operation to the virtual machine

2 When the memory usage information is displayed for the first time, no more pressing "cause GC"

Heap视图界面会定时刷新,在对应用的不断的操作过程中就可以看到内存使用的变化

3 Memory usage information parameters according to the name can know its meaning, do not know the specific meaning of the friend self-use tools (Youdao, the word bully to find out)

知道工具使用了,那么如何才能知道我们的程序是否有内存泄漏的可能性呢。这里需要注意一个值:Heap视图中部有一个Type叫做data object,即数据对象,也就是我们的程序中大量存在的类类型的对象。在data object一行中有一列是“Total Size”,其值就是当前进程中所有Java数据对象的内存总量,如果大家想要看“Total Size”是分配的具体信息可以点击“data object这一行来查看详细信息,如”(大家看不清楚的点击看大图)
In general, the size of the value "total size" on the data object line determines if there is a memory leak. It can be judged as follows:
 a) 不断的操作当前应用,同时注意观察data object的Total Size值; b) 正常情况下Total Size值都会稳定在一个有限的范围内,也就是说由于程序中的的代码良好,没有造成对象不被垃圾回收的情况,    所以说虽然我们不断的操作会不断的生成很多对 象,而在虚拟机不断的进行GC的过程中,这些对象都被回收了,    内存占用量会会落到一个稳定的水平; c) 反之如果代码中存在没有释放对象引用的情况,则data object的Total Size值在每次GC后不会有明显的回落,    随着操作次数的增多Total Size的值会越来越大,直到到达一个上限后导致进程被杀掉。

Please follow my GitHub.


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.