zoukankan      html  css  js  c++  java
  • eclipse java MemoryAnalyzer 查询内存泄漏 环境配置

    简单记录下java用MemoryAnalyzer分析内存泄漏问题!

    首先,内存不足的时候,会报错 Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded类似的错误!

    这时候会生成java_pid3708.hprof类似的文件,这个文件就是MemoryAnalyzer需要分析的文件!

    写个例子,快速生成这个文件!

     1 public class TestMain {
     2 
     3     public static void main(String[] args) {
     4         
     5         List<TestMain> ary =new ArrayList<TestMain>();
     6         while(true){
     7             ary.add(new TestMain());
     8         }
     9         
    10     }
    11 
    12 }

    运行配置:

    等一会就会出现如下

    java.lang.OutOfMemoryError: GC overhead limit exceeded
    Dumping heap to java_pid10996.hprof ...
    Heap dump file created [780500156 bytes in 3.037 secs]
    Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
    。。。。。

    此时去工程根目录下查找*.hprof的文件

    下载 MemoryAnalyzer-1.8.1.20180910-win32.win32.x86_64.zip  地址:https://www.eclipse.org/mat/downloads.php

    当然,根据你的环境不同自行选择版本!

    下载后直接解压,发现 MemoryAnalyzer.exe 和 MemoryAnalyzer.ini 

    直接运行MemoryAnalyzer.exe载入hprof文件!至于如何分析,自己慢慢学吧,我这里仅做记录!

    出问题看这里:应该就是mat的运行内存不够,hprof太大造成的

    为了更有效率的使用 MAT,我们可以配置一些环境参数。因为通常而言,分析一个堆转储文件需要消耗很多的堆空间,为了保证分析的效率和性能,在有条件的情况下,我们会建议分配给 MAT 尽可能多的内存资源。你可以采用如下两种方式来分配内存更多的内存资源给 MAT。

    一种是修改启动参数 MemoryAnalyzer.exe-vmargs -Xmx4g

    另一种是编辑文件 MemoryAnalyzer.ini,在里面添加类似信息 -vmargs– Xmx4g。

    说明:

    1. MemoryAnalyzer.ini中的参数一般默认为-vmargs– Xmx1024m,这就够用了。假如你机器的内存不大,改大该参数的值,会导致MemoryAnalyzer启动时,报错:Failed to create the Java Virtual Machine。

    2.当你导出的dump文件的大小大于你配置的1024m(说明1中,提到的配置:-vmargs– Xmx1024m),MAT输出分析报告的时候,会报错:An internal error occurred during: "Parsing heap dump from XXX”。适当调大说明1中的参数即可。

  • 相关阅读:
    JS-只能输入中文和英文
    强密码正则表达式
    java 实体序列化的意义
    数据库中存在0,1,2.....或者1,null,2 排序时让0或者null在最后的sql语句
    Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile 解决办法
    C#中的线程(二) 线程同步基础
    C#中的线程(一)入门
    C#多线程编程
    C#(asp.net )读取ASHX文件(一般处理程序)
    Oracle中三种循环(For、While、Loop)
  • 原文地址:https://www.cnblogs.com/ruber/p/10289185.html
Copyright © 2011-2022 走看看