• 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中的参数即可。

  • 相关阅读:
    第三篇——第二部分——第三文 配置SQL Server镜像——域环境
    DOS命令学习(从入门到精通)
    Cocos2d-x3.0 LoadingBar
    微信对接HIS——微信可查检验结果
    微信iOS SDK文档总结
    Azure编程笔记(4):配置Cloud Service的证书
    android的ViewPager和Animation的一些使用(一)
    小虾米的鳄鱼梦
    Hadoop源码分析21:namenode概要
    Hadoop源码分析20:datanode概要
  • 原文地址:https://www.cnblogs.com/ruber/p/10289185.html
Copyright © 2020-2023  润新知