013 - 关于GC root: Native Stack | MAT分析

Posted N!CE波

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了013 - 关于GC root: Native Stack | MAT分析相关的知识,希望对你有一定的参考价值。

 
Question:
 
I have some third library code that I run and after some time I run into OutOfMemoryError. So I fired up the Eclipse MAT and analyzed the memory. Now it seems the memory can‘t be disposed because there is an object that is a shown as GC root: Native Stack
 
 
Answer:
 
Objects being shown as GC root: Native Stack turned out to be a problem of the Eclipse Debugger. When the application was started without the debugger (i.e. with ‘run‘ instead of ‘debug‘) the problem disappeared. This was also the reason that I couldn‘t find the code where the objects where used in JNI inside my project (cause they weren‘t).
The same problem appears when using IntelliJ Debugger
 
 
简单说:
   通过Eclipse或者IntelliJ  采用debug模式启动程序时,发生内存溢出错误后,由于存在 GC root: Native Stack,导致发生错误的方法中创建的对象无法释放 (正常情况下,发生错误后,方法调用结束,对象会被正常释放的)。
解决方法:采用run运行(非debug模式),就不会存在该问题了013 - 关于GC root: Native Stack  |  MAT分析

以上是关于013 - 关于GC root: Native Stack | MAT分析的主要内容,如果未能解决你的问题,请参考以下文章

JVMGC 可达性分析中哪些算是GC ROOT?

JVM对象A和B循环引用,最后会不会不被GC回收?-------关于Java的GC机制

GC笔记--Native线程

关于GC(中):Java垃圾回收相关基础知识

墨者靶场 Apache Struts2远程代码执行漏洞(S2-013)复现

墨者靶场 Apache Struts2远程代码执行漏洞(S2-013)复现