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分析
原文地址:https://www.cnblogs.com/756623607-zhang/p/8993885.html