记一次jmap和MAT的线上排查

论坛 期权论坛 脚本     
匿名网站用户   2020-12-19 21:37   48   0

1.线上代码:

package testSpringMVC;

public class User {
     private String id;  
     private String name;  
   
     public String getId() {  
         return id;  
     }  
   
     public void setId(String id) {  
         this.id = id;  
     }  
   
     public String getName() {  
         return name;  
     }  
   
     public void setName(String name) {  
         this.name = name;  
     }  
   
     public User(String id, String name) {  
         super();  
         this.id = id;  
         this.name = name;  
     }  
}
package testSpringMVC;

import java.util.ArrayList;
import java.util.List;

public class Test {
 public static void main(String[] args) {  
     List<User> list = new ArrayList<User>();  
     for (int i = 1; i < 10000; i++) {  
         User o = new User(i + "", System.currentTimeMillis() + "");  
         list.add(o);  
         o = null;  
     }  
     System.out.println("end");  
     try {  
         Thread.sleep(100000000l);  
     } catch (InterruptedException e) {  
         e.printStackTrace();  
     }  
 }  
}
2.用jps -l 查看进程

3.先用jmap -histo 1357瞅一下


看到没,User有很多!

4.我们在Eclipse安装完MAT之后就可以分析了


然后通过OOL查询


也就是说这个是null,但是仍然有强引用存在,gc的时候是不能回收的,这样就会出现内存的溢出问题


分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:1136255
帖子:227251
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP