参考文档:
使用 Eclipse Memory Analyzer 检测内存泄漏问题
http://www.cnblogs.com/dotnetdoor/archive/2008/06/09/1216125.html
http://tivan.iteye.com/blog/1487855
http://blog.csdn.net/kongls08/article/details/8525048
http://blog.csdn.net/gzh0222/article/details/8363032
http://blog.csdn.net/gzh0222/article/details/8349775
测试代码:
strings = new Vector(); for (int i = 0; i < 20000; i++) { System.out.println("o"); Person string = new Person("jhy fdsafdsf"); strings.add((Object) string); string = null; } System.out.println("ok"); while (true) { try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
有意进行内存的泄露,string = null实际上释放不了被Vector引用的new Person对象的
如果要释放,必须进行strings = null;
运行代码,然后dump该进程的内存
jmap -dump:format=b,file=heap.bin 2724 (file是保存的文件名 ,bin 2724是该java进程的PID)
利用下载的MemoryAnalyzer进行分析: