如何识别JNI全局引用内存泄漏的原因? [英] How to identify the cause of a JNI global reference memory leak?

查看:461
本文介绍了如何识别JNI全局引用内存泄漏的原因?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Tomcat,在停止我的web应用程序之后,仍然有对我的web应用程序的类加载器实例的引用。
结果是,大量的内存(主要与静态数据有关)不会被释放。迟早会导致 OutOfMemoryError

我花了一个堆转储 code>,我意识到它由 JNI全局引用 防止类加载器将 垃圾回收



我的应用程序不使用JNI 。我也没有使用 Apache Tomcat原生库。我正在使用Sun / Oracle JDK。

我想查找此全局参考的起因/来源。
(我的猜测是JVM内部引用类加载器 - 但是为什么/在哪里?)。



问题:


  • 有哪些方法/工具集可以实现这一目标?


UPDATE



好像bestsss是正确的,JNI全局引用已由jvm调试模式引入。这帮助了我,但它没有回答这个问题,所以我仍然好奇地想要得到对未来可能有帮助的问题的答案。

解决方案<除了明显的情况:线程还有一个:

您是否在调试模式下使用您的应用程序?

/ p>

JVM不包含除系统之外的任何类加载器的引用,但它并不关心您。 JNI引用的其余部分是线程或只是调试保持对象(假设您不使用JNI并自己锁定对象)。

JNI引用只是根,编辑你的答案并发布那些引用所持有的对象。


I'm using Tomcat and after stopping my web application there's still a reference to the classloader instance of my web application. With the consequence that a notable amount of memory (mostly related to static data) will not be freed. Sooner or later this results in an OutOfMemoryError.

I took a heap dump and I realized that its held by a JNI global reference which prevents that the classloader will be garbage collected.

My application does not use JNI. I am also not using the Apache Tomcat Native Library. I am using a Sun/Oracle JDK.
I'd like to track down the cause/origin of this global reference. (My guess is that the JVM internally references the classloader - but why/where?).

Question:

  • Which approaches/toolsets exists to achieve this?

UPDATE

It seems that bestsss is right and the JNI global references has been introduced by the jvm debug mode. This helped me out but it does not answer the question so I am still curious to get an answer to the question which might be helpful in the future.

解决方案

Besides the obvious case: Threads, there is one more:

Are you using your application in debug mode?

The JVM does not hold references to any classloader besides the system one, but it doesn't concern you. The rest of JNI references are either Threads or just debug held objects (provided you don't use JNI and lock the objects down yourself).

JNI references are just roots, edit your answer and post what exactly objects are held by those references.

这篇关于如何识别JNI全局引用内存泄漏的原因?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆