下載MAT工具,下載地址:https://www.eclipse.org/mat/d...,解壓後,windows的話直接運行MemoryAnalyzer.exe便可php
寫一段會oom的代碼java
public class GCtest { private String[] val = new String[10000]; public static void main(String[] args) { Map<String, GCtest> map = new HashMap<>(); int i = 0; while (true) { map.put(String.valueOf(i), new GCtest()); i++; } } }
添加運行參數windows
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=your path 不加HeapDumpPath 默認當前目錄
運行代碼,生成.hprof文件,運行mat分析工具打開文件,能夠看出hashmap裏面的對象遲遲沒有釋放微信