1. Eclipse Memory Analyzer安装

Help ->Eclipse Marketplace,搜索Memory,点击install,->confirm->同意证书内容->finish。安装完成后重启。
参考: Eclipse安装内存分析工具(Memory Analyzer) 
2. 修改配置
Window-> Preferences->General->选中Show heap status

内存映像分析工具Eclipse Memory Analyzer

3. Java堆内存溢出异常测试

public class HeapOOM {
    
    static class OOMObject{
        
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        List<OOMObject> list = new ArrayList<OOMObject>();
        
        while(true){
            list.add(new OOMObject());
        }
    }

}

4. 配置运行参数
Run Configurations-->Arguments-->VM arguments中添加:-Xms20m -Xmx20m -XX:+HeapDumpOnOutOfMemoryError

内存映像分析工具Eclipse Memory Analyzer

5. 运行代码后,eclipse刷新工程,可以看见生成的.hprof文件

内存映像分析工具Eclipse Memory Analyzer

双击打开.hprof文件,如图

内存映像分析工具Eclipse Memory Analyzer

内存映像分析工具Eclipse Memory Analyzer

 参考:https://www.cnblogs.com/dennyzhangdd/p/5647469.html

相关文章:

  • 2022-01-22
  • 2021-06-15
  • 2021-08-15
  • 2021-08-19
  • 2021-08-13
  • 2021-10-26
  • 2021-12-15
猜你喜欢
  • 2022-12-23
  • 2021-09-16
  • 2021-10-20
  • 2021-06-15
  • 2021-07-13
  • 2021-06-17
  • 2021-12-15
相关资源
相似解决方案