Android Memory leak test

Source: Internet
Author: User

This article references: http://blog.csdn.net/amy0428/article/details/7057282

Under Android, how to test for memory leaks, in addition to long-running indirect tests, is there a tool to help us with this test?

First, install the MAT

Similar to the installation of other plug-ins, the mat supports two installation methods, one "standalone", which means that the user does not have to install the Eclipse IDE environment, the mat is run as a standalone Eclipse RCP application, and the other is "integrated", which means that the mat can also be used as a ecli Part of the PSE IDE, integrated with the existing development platform.

Online is eclipse, click Help,install New software,work with in the input URL, remember to click Add,next,next.

If not, do not worry, download your own installation, the link is as follows:

(: Www.eclipse.org/downloads/download.php?file=/mat/1.1.1/MemoryAnalyzer-1.1.1.201108240735.zip)

Http://www.eclipse.org/downloads/download.php?file=/mat/1.1.1/MemoryAnalyzer-1.1.1.201108240735.zip

Install new Software,achieve, enter the zip file that you just downloaded, Next,nex installation is done.

Second, Configure the environment parameters

After the installation is complete, some configuration work is required in order to use the MAT more efficiently. Because in general, it takes a lot of heap space to analyze a heap dump file, and in order to ensure the efficiency and performance of the analysis, we recommend allocating to the MAT as much memory resources as possible in a conditional situation. There are two ways you can allocate memory for more memory resources to MAT.

One is to modify the startup parameters memoryanalyzer.exe-vmargs-xmx4g

The other is to edit the file Memoryanalyzer.ini, add similar information inside the-vmargs–xmx4g. Build the. HPROF file: Select the process you want to test in Ddms in Eclipse, then click Update Heap and dump HPROF file two button.

The. hprof file is automatically saved on your computer and the. hprof file is copied to the \ android-sdk-windows\tools directory on your PC. The file generated by DDMS cannot be opened directly on the mat and needs to be converted.

Run cmd Open command line, CD to \ Android-sdk-windows\tools directory, and enter command Hprof-conv xxxxx.hprof Yyyyy.hprof, where Xxxxx.hprof is the original file, Yyyyy.hprof is the converted file. The converted files are automatically placed in the Android-sdk-windows\tools directory.

OK, so far, the. hprof file is processed and can be used to analyze memory leaks. Open Mat:

In Eclipse, click Windows→open perspective→other→memory Analysis to import the. hprof file

Click File→open file in the mat, browse to the. hprof files that you just converted, and cancel the auto-Generate report, click Dominator Tree and Group by package, select your own defined package category right-click, SELECT list Objects→with incoming references in the pop-up menu.

All suspicious classes are listed, right-clicking on an item and selecting Path to GC roots→exclude Weak/soft references further filters out all memory-leaking classes associated with the program. As a result, you can trace to a class in your code that produces a leak. Because all the suspicious places are listed here, RD further analysis is needed to determine.

Android Memory leak test

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.