1.生成dump文件代码
import java.util.*; /** * @Date {DATE} {TIME} **/ public class Test { public static void main(String[] args) { List<String> list=new ArrayList<>(); int i=0; while (true){ list.add("test"); } } }
2.编译
javac Test.java
java -Xmx10m Test
3.生成dump文件
java -Xmx10m -XX:+HeapDumpOnOutOfMemoryError Test
4.分析dump文件(java_pid57220.hprof)
IBM heapAnalyzer
参考:
https://blog.csdn.net/xu1314/article/details/7711768
https://mp.weixin.qq.com/s/Hv1yeeSbQpSkLBS5-cUVUA