How to Find memory leaks in Java + JNI + C++ process

谁说胖子不能爱 提交于 2019-12-20 03:23:10

问题


I have project written in java that using JNI uses a C++ library. All the code was written by us, so I have all the source code.

After few hours the machine runs out of memory although my process just iterate over files and all the memory regarding the previous file deleted.

I'm sure that there is a memory leak, usually I use Valgrind, but it seems he can't cope with Java very well and believes that the JVM is leaking, even for "hello world" java project.

I've tested the C++ parts (the major flows) with unit-tests and used valgrind on the unit-tests, but couldn't find any leakage. It doesn't prove anything because there are many potential flows I could've missed.

My major question, how can I find my leak ?

It will be extremely helpful to know who is consuming the memory, the java or the native part ? they are in the same process.

Thanks.


回答1:


You can use jemalloc to debug native memory leaks. This blog post has a detailed example of using jemalloc to debug a native memory leak in java applications.




回答2:


From my experience, Valgrind is actually usable with the JVM, and it remains the best tool to hunt leaks in C/C++ code, even with JNI. So your question kinda contains the answer that you need ;)

If you fail to use JNI and Valgrind together, please refer to Valgrind and Java.



来源:https://stackoverflow.com/questions/33334126/how-to-find-memory-leaks-in-java-jni-c-process

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