http://smallnetvisitor.iteye.com/blog/1826434

 

User.java

class User {  
    private String id;  
    private String name;  
  
    public String getId() {  
        return id;  
    }  
  
    public void setId(String id) {  
        this.id = id;  
    }  
  
    public String getName() {  
        return name;  
    }  
  
    public void setName(String name) {  
        this.name = name;  
    }  
  
    public User(String id, String name) {  
        super();  
        this.id = id;  
        this.name = name;  
    }  
  
}

main方法:

public static void main(String[] args) {  
    List<User> list = new ArrayList<User>();  
    for (int i = 1; i < 10000; i++) {  
        User o = new User(i + "", System.currentTimeMillis() + "");  
        list.add(o);  
        o = null;  
    }  
    System.out.println("end");  
    try {  
        Thread.sleep(100000000l);  
    } catch (InterruptedException e) {  
        e.printStackTrace();  
    }  
}


运行user任务管理器查看到的pid号:

eclipse中mat插件使用eclipse中mat插件使用

 

基于jmap导出的堆信息:

eclipse中mat插件使用eclipse中mat插件使用

 

用装了mat插件的eclipse打开firstHeap.bin文件

eclipse中mat插件使用

选择Leak Suspects Reports模式,finish

eclipse中mat插件使用

在底部的Actions有

(1)histogram
列出了有每个种有多少实例,每种类型的实例集合的 shallow size 和  retained size . shallow size指的是对象所消耗的内存大小,如每个对象引起消耗4个字节,或者8个字节,取决于你的操作系统(32位,还是64位), retained size的概念依赖于Retained set 的概念,Retained set 指的是当对象X被回收时,所有被垃圾回收器移除的对象集合,
Retained size 即是Retained set所保持的内存大小。

eclipse中mat插件使用

当然histogram 不仅可以通过类进行数据组织,还可以通过class loader, packages or superclass .来进行数据的组织。

eclipse中mat插件使用

eclipse中mat插件使用

(2)The Dominator Tree
列出了堆中最大的对象,第二层级的节点表示当被第一层级的节点所引用到的对象,当第一层级对象被回收时,这些对象也将被回收。这个工具可以帮助我们定位对象间的引用情况,垃圾回收时候的引用依赖关系。
eclipse中mat插件使用

(3)Path to GC Roots
被JVM持有的对象,如当前运行的线程对象,被systemclass loader加载的对象被称为GC Roots, 从一个对象到GC Roots的引用链被称为Path to GC Roots, 通过分析Path to GC Roots可以找出JAVA的内存泄露问题,当程序不在访问该对象时仍存在到该对象的引用路径。
eclipse中mat插件使用

eclipse中mat插件使用

eclipse中mat插件使用

 

点击details

eclipse中mat插件使用eclipse中mat插件使用

eclipse中mat插件使用

 

这些对象有可能会溢出,然后我们打开OQL窗口

eclipse中mat插件使用eclipse中mat插件使用

 

执行如下OQL语句

eclipse中mat插件使用eclipse中mat插件使用

 

eclipse中mat插件使用

也就是说这个是null,但是仍然有强引用存在,gc的时候是不能回收的,这样就会出现内存的溢出问题

 

不懂就按F1,关于OQL有详细介绍,

或进官网  mat Querying Heap Objects:http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.mat.ui.help%2Ftasks%2Fqueryingheapobjects.html

eclipse中mat插件使用

一步一个脚印,方便自己复习,该出手时就出手,有错误,一定要指正,非常感谢,共同进步!

 

http://smallnetvisitor.iteye.com/blog/1826434

 

User.java

class User {  
    private String id;  
    private String name;  
  
    public String getId() {  
        return id;  
    }  
  
    public void setId(String id) {  
        this.id = id;  
    }  
  
    public String getName() {  
        return name;  
    }  
  
    public void setName(String name) {  
        this.name = name;  
    }  
  
    public User(String id, String name) {  
        super();  
        this.id = id;  
        this.name = name;  
    }  
  
}

main方法:

public static void main(String[] args) {  
    List<User> list = new ArrayList<User>();  
    for (int i = 1; i < 10000; i++) {  
        User o = new User(i + "", System.currentTimeMillis() + "");  
        list.add(o);  
        o = null;  
    }  
    System.out.println("end");  
    try {  
        Thread.sleep(100000000l);  
    } catch (InterruptedException e) {  
        e.printStackTrace();  
    }  
}


运行user任务管理器查看到的pid号:

eclipse中mat插件使用eclipse中mat插件使用

 

基于jmap导出的堆信息:

eclipse中mat插件使用eclipse中mat插件使用

 

用装了mat插件的eclipse打开firstHeap.bin文件

eclipse中mat插件使用

选择Leak Suspects Reports模式,finish

eclipse中mat插件使用

在底部的Actions有

(1)histogram
列出了有每个种有多少实例,每种类型的实例集合的 shallow size 和  retained size . shallow size指的是对象所消耗的内存大小,如每个对象引起消耗4个字节,或者8个字节,取决于你的操作系统(32位,还是64位), retained size的概念依赖于Retained set 的概念,Retained set 指的是当对象X被回收时,所有被垃圾回收器移除的对象集合,
Retained size 即是Retained set所保持的内存大小。

eclipse中mat插件使用

当然histogram 不仅可以通过类进行数据组织,还可以通过class loader, packages or superclass .来进行数据的组织。

eclipse中mat插件使用

eclipse中mat插件使用

(2)The Dominator Tree
列出了堆中最大的对象,第二层级的节点表示当被第一层级的节点所引用到的对象,当第一层级对象被回收时,这些对象也将被回收。这个工具可以帮助我们定位对象间的引用情况,垃圾回收时候的引用依赖关系。
eclipse中mat插件使用

(3)Path to GC Roots
被JVM持有的对象,如当前运行的线程对象,被systemclass loader加载的对象被称为GC Roots, 从一个对象到GC Roots的引用链被称为Path to GC Roots, 通过分析Path to GC Roots可以找出JAVA的内存泄露问题,当程序不在访问该对象时仍存在到该对象的引用路径。
eclipse中mat插件使用

eclipse中mat插件使用

eclipse中mat插件使用

 

点击details

eclipse中mat插件使用eclipse中mat插件使用

eclipse中mat插件使用

 

这些对象有可能会溢出,然后我们打开OQL窗口

eclipse中mat插件使用eclipse中mat插件使用

 

执行如下OQL语句

eclipse中mat插件使用eclipse中mat插件使用

 

eclipse中mat插件使用

也就是说这个是null,但是仍然有强引用存在,gc的时候是不能回收的,这样就会出现内存的溢出问题

 

不懂就按F1,关于OQL有详细介绍,

或进官网  mat Querying Heap Objects:http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.mat.ui.help%2Ftasks%2Fqueryingheapobjects.html

eclipse中mat插件使用

相关文章:

  • 2021-06-19
  • 2021-09-03
  • 2021-07-30
  • 2021-07-21
  • 2021-12-25
  • 2021-12-26
  • 2022-12-23
猜你喜欢
  • 2021-12-30
  • 2022-01-21
  • 2021-10-17
  • 2022-12-23
  • 2021-09-24
  • 2022-01-18
  • 2021-12-29
相关资源
相似解决方案