我发现哪种对象导致内存泄漏,现在怎么办? [英] I found what kind of objects are causing a memory leak, now what?

查看:118
本文介绍了我发现哪种对象导致内存泄漏,现在怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行的进程中,每30分钟左右使用jmap -histo命令,我发现了一种显然是内存泄漏的对象(在桌面应用程序中).

Using the jmap -histo command on a running process, every 30 minutes or so, I found one kind of object that is obviously a memory leak (in a desktop app).

造成泄漏的对象( Ie 是唯一一种其实例数随时间增长并且数量巨大并且增长的对象)是 int [] .

The object responsible for the leak (I.e. the only kind of object whose number of instances grows over time, and by a huge amount) is int[].

我怀疑是BufferedImage的罪魁祸首,但我对此不确定(我非常注意冲洗/清零BufferedImage,但我仍然认为这是泄漏的根源).

I suspect BufferedImage to be the culprit but I'm not sure about that (I took great care about flushing/nullifying BufferedImages but I still think that's where the leak hangs).

但是,我还在程序的另一部分中使用了int [],但我不确定是否从哪里泄漏了. jmap -histo的输出对我来说太薄"了.

However I'm also using int[] in another part of the program and I'm simply not sure as to where the leak is coming from. The output of jmap -histo is a bit too "thin" to my liking.

现在如何确定int[]的泄漏发生位置.

How can I now pinpoint where the leak(s) of int[] are occuring.

通过这种方式,我想指出一个简单的jmap -histo可以有多棒:我敢肯定,对于许多对象而言,仅查看实例数和所使用的内存就足以发现泄漏,而无需需要进一步分析.

By the way I'd like to point out how great a simple jmap -histo can be: I'm sure that for a lot of objects simply seeing the number of instances and memory used is enough to spot a leak, without needing further analysis.

但是,就我而言,我还需要其他东西.

However in my case I need something else.

我的问题不是哪种工具可以发现泄漏.我的问题是:

My question is not what kind of tools allow to spot a leak. My question is:

知道我的应用程序(或我的应用程序正在使用的API)正在泄漏 int [] ,我可以采取哪些步骤(例如,使用您最喜欢的探查器)来希望找到泄漏?

Knowing that my app (or an API that my app is using) is leaking int[], what steps can I take (using your favorite profiler, for example) to, hopefully, find the leaks?

该工具必须能够在Java 1.5 OS X 10.4 Apple JVM上运行.

推荐答案

我个人不建议jProfiler的功能,因此我建议首先使用Eclipse MAT.然后,当您加载堆转储时,您可以检查一些int []的传入引用.您可以弄清楚是谁创建了数组,并查看哪个保持类确实在创建大量数组.

I would recommend first using Eclipse MAT as I dont know, personally, the capabilities of jProfiler. Then when you load your heap dump you can check some of the int[]'s incoming references. You can thin pin point who created the arrays and see which holding class is really creating the massive amount.

这篇关于我发现哪种对象导致内存泄漏,现在怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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