A brief introduction to the 1.MAT
MAT(Memory Analyzer Tool) 是基于heap dumps来进行内存分析的工具,一个基于Eclipse的内存分析工具,是一个快速、功能丰富的JAVA heap分析工具,它可以帮助我们查找内存泄漏和减少内存消耗。
2. Download and install
- http://www.eclipse.org/mat/downloads.php
- The address contains a plug-in package and a standalone installation package, such as
- Choose the right download for you
- I chose the zip package here and installed it in Eclipse.
3. Get the. hprof file
In Android Studio, open the Android monitor panel, select Memory, click on the left Dump Java heap button dump RAM information, the project will be generated under the captures folder. hprof file, (see in the folder), as shown in.
But the file generated above does not open in the mat, we need to use the Hprof-conv tool to turn, Hprof-conv under the SDK Platform-tools, WinDOS under Double-click Start, Ubuntu under./hprof-conv Start, The conversion command is as follows
hprof-conv 输入文件路径 输出文件路径
The results show:
, so we can open it in the mat.
Of course, we can also start DDMS directly in eclipse, click Dump XXX, then stop, will be automatically opened by the mat, such as:
Note the following actions area, which is the object we need to focus on.
4. Useful several functions 4.1.Histogram: List objects in memory, number of objects and size
4.2 Dominator Tree lists the largest objects and their dependent on the surviving object (size is sorted by retained heap)
4.3 Top consumers: List the largest object by graph
4.4 The thread information for the Thread_overview app.
4.5 Viewing GC reference relationships
Under Dominator tree attempt, click on an object, right-path to the GC roots-> with all references, and view the reference relationship. Such as
See, I have only one reference here, the complex object is a reference chain, not more said,
5. How to know if there is a memory leak
It said so much, however, there is no disorderly use, confused to see some of the pictures, confused to know some views, but, mom, we do not know how to see which memory leaks. However, in 4.5 we can see the GC roots can see the reference relationship, then we can see through him, through the layer of reference relationships, we can go back to the final reference point, by combining code analysis and checking reference types and referenced classes and so on.
6. Summary
Well, with so much coming down, I've only learned the basics, and more usage needs to be understood at work.
At last. Give a few reference links.
- The use of Mat one
- The use of Mat two
Android Performance Optimization-mat tool easy to use