Memory Analyzer分析内存泄漏
程序员文章站
2022-03-06 12:17:38
Memory Analyzer分析内存泄漏模拟一次内存溢出程序不断地向ArrayList添加对象,直至溢出public class User { String userName; String passWord; public String getUserName() { return userName; } public void setUserName(String userName) { this.userName...
Memory Analyzer分析内存泄漏
模拟一次内存溢出
- 程序不断地向ArrayList添加对象,直至溢出
public class User {
String userName;
String passWord;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassWord() {
return passWord;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
}
import java.util.ArrayList;
import java.util.List;
public class jvmMemoryOut {
public static void main(String[] args) {
List<Object> listObject = new ArrayList<>();
for (int i = 0; i < 100000; i++) {
System.out.println("i:" + i);
User user = new User();
user.setUserName("小明");
user.setPassWord("123456");
listObject.add(user);
}
System.out.println("添加成功...");
}
}
- VM设置
-Xms1m -Xmx2m -XX:+PrintGCDetails -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=C:\Users\0096001939\Desktop\dump
3. 运行后获得dump文件
Memory Analyzer打开dump文件
-
查看到概览,然后我们打开details
-
通过details我们看到多个user在一个list中,撑爆了内存
-
查看user所在线程的详情.
本文地址:https://blog.csdn.net/growing1224/article/details/112002370
上一篇: springBoot-Mybatis