How to find native memory leaks caused by a java code?

Deadly 提交于 2019-12-24 21:32:44

问题


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?

Thanks!!


回答1:


JConsole can help viewing Java memory usage.

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.

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).




回答2:


java has free tool known as native memory tracker. You can baseline it and then generate a difference at regular intervals.

Using this difference you can easily identify which part of memory is leaking memory.



来源:https://stackoverflow.com/questions/6754923/how-to-find-native-memory-leaks-caused-by-a-java-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!