如何查找由Java代码引起的本机内存泄漏? [英] How to find native memory leaks caused by a java code?

查看:94
本文介绍了如何查找由Java代码引起的本机内存泄漏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java代码,该代码基本上可以创建,显示和销毁诸如球体的几何对象,并进行一定数量的迭代.我使用本机opengl调用来显示这些对象.随着本机内存不断增加,代码中存在一些内存泄漏.我正在通过查看任务管理器中的"Workink Set"内存来检查本机内存.但是,当我运行netbeans Profiler时,找不到任何内存泄漏.那么,如何查找本机内存泄漏?有没有可用的工具来显示本机和堆内存使用情况?

I have a java code which basically creates, displays and then destroys geometry objects like spheres for a certain number of iterations. I use native opengl calls for displaying these objects. There is some memory leak in the code as the native memory keeps on increasing. I am checking the native memory by viewing the "Workink Set" memory in Task manager. However, when I ran the netbeans profiler, I couldn't find any memory leak. So, how to find the native memory leak? Are there any tools available to visualize both the native and heap memory usage?

谢谢!

推荐答案

JConsole可以帮助查看Java内存使用情况.

JConsole can help viewing Java memory usage.

如果您正在使用现有的Java-OpenGL库,则可能使用的是可能无法释放的直接缓冲区.如果您自己编写了本机代码,则可能不适用.

If you are using an existing Java-OpenGL library, it is possible it is using direct buffers which might not be getting freed. If you have written the native code yourself this probably wont apply.

对于本机内存,如果您的Java-OpenGL库使用的是直接缓冲区,那么我仅在JDK 7中注意到(我正在运行预发行版),在JConsole中可见一些额外的MBean,而在以前的版本中不存在这些MBean.这可能会有所帮助.在JConsole的java.nio.BufferPool下的MBeans选项卡中查看.在直接" bean下,您可以看到直接缓冲区已用完的内存.如果这种情况持续下去,则可能表明存在直接的内存泄漏(可能是由于未在Java代码中关闭/布置OpenGL资源).

For native memory, if your Java-OpenGL library is using direct buffers, I've noticed in JDK 7 only (I'm running the prerelease) that there are some extra MBeans visible in JConsole that are not there in previous versions that may help. Take a look in the MBeans tab in JConsole under java.nio.BufferPool. Under the 'direct' bean you can see the memory used up by direct buffers. If this keeps going up, it might indicate a direct memory leak (possibly because of not closing/disposing OpenGL resources in your Java code).

这篇关于如何查找由Java代码引起的本机内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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