什么是'JNI全球参考' [英] What is 'JNI Global reference'

查看:79
本文介绍了什么是'JNI全球参考'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jProfiler在Java swing应用程序中查找内存泄漏。我已经确定了JFrame的实例,它在计数中不断增长。

I am using jProfiler to find memory leaks in a Java swing application. I have identified instances of a JFrame which keeps growing in count.

此框架已打开,然后关闭。

This frame is opened, and then closed.

使用jProfiler,并查看GC根路径只有一个参考,'JNI全球参考'。

Using jProfiler, and viewing the Paths to GC Root there is only one reference, 'JNI Global reference'.

这是什么意思?为什么它挂在框架的每个实例上?

What does this mean? Why is it hanging on to each instance of the frame?

推荐答案

维基百科对 Java Native Interface ,本质上它允许Java和用其他语言编写的本机操作系统库之间的通信。

Wikipedia has a good overview of Java Native Interface, essentially it allows communication between Java and native operating system libraries writen in other languages.

JNI全局引用容易出现内存泄漏,因为它们不会自动进行垃圾回收,程序员必须明确释放它们。如果您没有自己编写任何JNI代码,则您使用的库可能存在内存泄漏。

JNI global references are prone to memory leaks, as they are not automatically garbage collected, and the programmer must explicitly free them. If you are not writing any JNI code yourself, it is possible that the library you are using has a memory leak.

编辑 这里是关于本地vs.的更多信息全局引用,以及为什么使用全局引用(以及如何释放它们)

edit here is a bit more info on local vs. global references, and why global references are used (and how they should be freed)

这篇关于什么是'JNI全球参考'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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