如何在Java + JNI + C ++进程中查找内存泄漏 [英] How to Find memory leaks in Java + JNI + C++ process

查看:403
本文介绍了如何在Java + JNI + C ++进程中查找内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用Java编写的项目,该项目使用JNI使用C ++库. 所有的代码都是我们编写的,所以我有所有的源代码.

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.

我确定内存泄漏,通常我使用Valgrind,但似乎他不能很好地处理Java,甚至认为对于"hello world" java项目,JVM也在泄漏.

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.

我已经用单元测试测试了C ++部分(主要流程),并在单元测试中使用了valgrind,但是找不到任何泄漏.它什么也没证明,因为我可能错过了很多潜在的流程.

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 ?

了解谁在消耗内存,java或本机部分将非常有帮助?他们是在同一过程中.

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

谢谢.

推荐答案

您可以使用 jemalloc 调试本机内存泄漏.

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.

这篇关于如何在Java + JNI + C ++进程中查找内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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