原文:

  http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.mat.ui.help%2Fgettingstarted%2Fbasictutorial.html

Basic Tutorial

  This tutorial provides a "jumping-off place" to get familiar with Memory Analyzer.

 基本操作如下:

Step 1 - Getting a Heap Dump 创建 .hprof文件

  The Memory Analyzer works with heap dumps . Such a heap dump contains information about all Java objects alive at a given point in time. All current Java Virtual Machines can write heap dumps, but the exact steps depend on vendor, version and operation system. Find out more in the section Acquiring Heap Dumps .

  Open  a sample heap dump if you view this page inside the Eclipse help center.

  For the purpose of this tutorial, we use Java 6 and JConsole on Windows. Start your application with Java 6, then start <jre6>/bin/jconsole.exe and select the running application (in this case Eclipse):

  Then, select the operation dumpHeap from the com.sun.management.HotSpotDiagnostic MBean. The first parameter p0 is the full path to the heap dump file. Make sure you give it the file extension .hprof. The second parameter p1 should be left at true as we are only interested in live objects.

Step 2 - The Overview 概况

  Open the heap dump via File >  Open Heap Dump... to see the overview page.

  On the right, you'll find the size of the dump and the number of classes, objects and class loaders.

  Right below, the pie chart gives an impression on the biggest objects in the dump. Move your mouse over a slice to see the details of the objects in the object inspector on the left. Click on any slice to drill down and follow for example the outgoing references.

Step 3 - The Histogram 柱状图查看某个类分配的对象数,注意要手动计算一次

  Select the histogram from the tool bar to list the number of instances per class, the shallow size and the retained size .

  The Memory Analyzer displays by default the retained size of individual objects. However, the retained size of a set of objects - in this case all instances of a particular class - needs to be calculated.

 在用mat分析 retained size 大小时,要手动计算一次。如下:

  To approximate the retained sizes for all rows, pick  icon from the tool bar. Alternatively, select a couple rows and use the context menu.

  Using the context menu , you can drill-down into the set of objects which the selected row represents. For example, you can list the objects with outgoing or incoming references. Or group the objects by the value of an attribute. Or group the collections by their size. Or or or...

  One thing that makes the Memory Analyzer so powerful is the fact that one can run any action on any set of objects. Just drill down and slice your objects the way you need them.

  Another important feature is the facility to group any histogram by class loader, packages or superclass .

  Any decent application loads different components by different class loaders. The Memory Analyzer attaches a meaningful label to the class loader - in the case of OSGi bundles it is the bundle id. Therefore it becomes a lot easier to divide the heap dump into smaller parts.

  More: Analyze Class Loader

  Grouping the histogram by packages allows to drill-down along the Java package hierarchy.

  Grouping the histogram by superclass provides an easy way to find for example all the subclasses of java.util.AbstractMap, etc...

Step 4 - The Dominator Tree 对象控制者树查看 对象控制关系

  The dominator tree displays the biggest objects in the heap dump. The next level of the tree lists those objects that would be garbage collected if all incoming references to the parent node were removed.

  The dominator tree is a powerful tool to investigate which objects keep which other objects alive. Again, the tree can be grouped by class loader (e.g. components) and packages to ease the analysis.

Step 5 - Path to GC Roots 查看被root gc 管理的对象 

  Garbage Collections Roots (GC roots) are objects that are kept alive by the Virtual Machines itself. These include for example the thread objects of the threads currently running, objects currently on the call stack and classes loaded by the system class loader.

  The (reverse) reference chain from an object to a GC root - the so called path to GC roots - explains why the object cannot be garbage collected. The path helps solving the classical memory leak in Java: those leaks exist because an object is still referenced even though the program logic will not access the object anymore.

  Initially, the GC root reached by the shortest path is selected.

Step 6 - The Leak Report 查看内存泄漏

  The Memory Analyzer can inspect the heap dump for leak suspects, e.g. objects or set of objects which are suspiciously big.

  Learn more in this blog posting: Automated Heap Dump Analysis: Finding Memory Leaks with One Click .

Android内存管理(10)MAT: 基本教程的更多相关文章

  1. Android 内存管理分析(四)

    尊重原创作者,转载请注明出处: http://blog.csdn.net/gemmem/article/details/8920039 最近在网上看了不少Android内存管理方面的博文,但是文章大多 ...

  2. 浅谈Android内存管理

    最近在网上看了不少Android内存管理方面的博文,但是文章大多都是就单个方面去介绍内存管理,没有能全局把握,缺乏系统性阐述,而且有些观点有误,仅仅知道这些,还是无法从整体上理解内存管理,对培养系统优 ...

  3. [Android Memory] Android内存管理、监测剖析

    转载自:http://blog.csdn.net/anlegor/article/details/23398785 Android内存管理机制: Android内存管理主要有:LowMemory Ki ...

  4. Android内存管理机制之一:low memory killer

    转载自http://www.miui.com/thread-29268-1-1.html 准备写这个专题之前,心里是有点忐忑的.首先Android内存管理机制相当复杂,想要讲清楚比较困难:其次对于绝大 ...

  5. 移动端测试===Android内存管理: 理解App的PSS

    Android内存管理: 理解App的PSS 原文链接:http://www.littleeye.co/blog/2013/06/11/android-memory-management-unders ...

  6. Android——内存管理基础

    内存收集概念 内存垃圾收集器(garbage collector) 概念:自定内存管理. 功能:分配内存.保证所有被引用的对象还在内存中.可以释放在运行的代码中不再引用的对象的内存. 垃圾收集器避免了 ...

  7. Android 内存管理之优化建议

    OOM(OutOfMemory)转:http://hukai.me/android-performance-oom/ 前面我们提到过使用getMemoryClass()的方法可以得到Dalvik He ...

  8. 深入理解Android内存管理原理(六)

    一般来说,程序使用内存的方式遵循先向操作系统申请一块内存,使用内存,使用完毕之后释放内存归还给操作系统.然而在传统的C/C++等要求显式释放内存的编程语言中,记得在合适的时候释放内存是一个很有难度的工 ...

  9. 【原创】Android内存管理-OnTrimMemory

    Application中有两个与内存管理相关的方法:onLowMemory()和 onTrimMemory(int level),源码如下 @CallSuper public void onLowMe ...

  10. 【原创】android内存管理-内存泄漏原因

    转载请注明出处 http://www.cnblogs.com/weiwangnuanyang/p/5704596.html 先讲一下内存泄漏的概念:内存泄露是指无用对象持续占有内存,或者内存得不到及时 ...

随机推荐

  1. 爬虫-----HTML解析

    对HTML的解析: 在解析复杂的HTML的页面时,需要避免一些问题,好让爬虫工作变得得心应手. • 寻找“打印此页”的链接,或者看看网站有没有HTML样式更友好的移动版(把自己 的请求头设置成处于移动 ...

  2. (五)python3 整型int

    int() Python 内置函数,用于将一个字符串或数字转换为整型. int(x, base=10)#以十进制转换x为整型(默认) >>>int() # 不传入参数时,得到结果0 ...

  3. hdu 1166敌兵布阵(线段树入门题)

    >>点击进入原题测试<< 思路:这两天在学线段树,这个题直接手敲一下线段树就行了,都没有用上懒人标记.入门题 cin,cout会超时,记得加std::ios::sync_wit ...

  4. 2.5.5.2 特殊文件:/dev/null 与 /dev/tty

        UNIX 系统提供了两个对Shell编程特别有用的特殊文件.       第一个文件 /dev/null ,就是大家所熟知的位桶(bit bucket).传送到此文件的数据都会被丢掉.换句话说 ...

  5. 纯JSP实现简单微信开发后台

    %@ page import="java.net.*" % %@ page import="java.math.*" % %@ page import=&quo ...

  6. [bzoj1232][Usaco2008Nov]安慰奶牛cheer_Kruskal

    安慰奶牛 cheer bzoj-1232 Usaco-2008 Nov 题目大意:给定一个n个点,m条边的无向图,点有点权,边有边权.FJ从一个点出发,每经过一个点就加上该点点权,每经历一条边就加上该 ...

  7. Ubuntu 16.04安装Synaptic Package Manager图形化APT管理工具

    安装: sudo apt-get install synaptic 启动:

  8. ORACLE EM的删除与创建

    手动删除ORACLE 10G EM 使用emca可以手动配置em! 配置em的过程中有一个环节要特别主要: 不论使用dbca还是使用emca -deconfig dbcontrol db -repos ...

  9. Android 属性动画(Property Animation) 全然解析 (上)

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38067475 1.概述 Android提供了几种动画类型:View Animat ...

  10. excel 补全全部空格

    首先全选列或者选中某列,按F5键.再按"定位条件„"button,选择空值,这样就把全部列的空格选中了,然后直接输入"你想要替换的值",再按Ctrl + 回车