追踪int [] [英] track down allocations of int[]

查看:135
本文介绍了追踪int []的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JMX上的JVisualVM中查看我的远程应用程序时,在空闲时会看到内存使用量的锯齿:

When viewing my remote application in JVisualVM over JMX, I see a saw-tooth of memory usage while idle:

进行堆转储并分析JVisualVM,我看到一大块内存是在几个大的 int [] 数组中没有引用和比较堆转储我可以看到似乎是这些正在采取记忆并由GC定期收回。

Taking a heap dump and analysing it with JVisualVM, I see a large chunk of memory is in a few big int[] arrays which have no references and by comparing heap dumps I can see that it seems to be these that are taking the memory and being reclaimed by a GC periodically.

我很好奇地追踪这些下来,因为它引发了我的兴趣,我自己的代码从来没有故意分配任何 int [] 数组。

I am curious to track these down since it piqued my interest that my own code never knowingly allocates any int[] arrays.

我使用了很多libs,如netty,所以罪魁祸首可以在别的地方。我有其他服务器具有相同的框架组合,但没有看到这个锯齿。

I do use a lot of libs like netty so the culprit could be elsewhere. I do have other servers with much the same mix of frameworks but don't see this sawtooth there.

如何发现谁分配?

推荐答案

取一个heapdump,找出对象持有的东西。一旦你知道什么对象拿着数组,你应该有一个简单的时间想法,弄清楚分配它们。

Take a heapdump and find out what objects are holding them. Once you know what objects are holding the arrays you should have an easy time idea figuring out what is allocating them.

它没有回答你的问题,但我的问题是:

It doesn't answer your question, but my question is:

你为什么关心?你已经告诉jvm垃圾收集器(GC),它可以使用高达1GB的内存。

Why do you care?

Java正在使用少于250M。

You've told the jvm garbage collector (GC) it can use up to 1GB of memory. Java is using less than 250M.

GC尝试在垃圾收集时清楚,并在垃圾收集时工作的难度。在你的图中,不需要内存。 jvm不会超过您设置的1GB限制。我没有理由GC应该尽量努力。不知道为什么你也会照顾。

The GC tries to be smart about when it garbage collects and also how hard it works at garbage collection. In your graph, there is no demand for memory. The jvm isn't anywhere near that 1GB limit you set. I see no reason the GC should try very hard at all. Not sure why you would care either.

垃圾收集器懒惰是一件好事。 GC的工作量越少,您应用程序的资源越多。

Its a good thing for the garbage collector to be lazy. The less the GC works, the more resources there are available for your application.

您是否尝试通过JVisualVM执行GC按钮触发GC?该按钮应触发停止世界垃圾收集操作。当图形位于锯齿之间时,请尝试一下 - 我预测使用量会下降到锯齿的底部或下方。如果是这样,那就证明内存锯齿只是垃圾堆积,GC正在做正确的事情。

Have you tried triggering GC via the JVisualVM "Perform GC" button? That button should trigger a "stop the world" garbage collection operation. Try it when the graph is in the middle of one of those saw tooth ramp ups - I predict that the usage will drop to the base of the saw tooth or below. If it does, that proves that the memory saw tooth is just garbage accumulation and GC is doing the right thing.

这是一个java swing应用程序的内存使用截图我使用:

Here is an screenshot of memory usage for a java swing application I use:

注意锯齿图案。

你说你担心int []。当我启动内存分析器并对其进行配置时,我可以看到int []

You said you are worried about int[]. When I start the memory profiler and have it profile everything I can see the allocations of int[]

基本上所有的分配来自ObjectOutputStream $ HandleTable.growEntries方法。看起来像分配的线程被转移到处理网络消息。

我怀疑它是由jmx本身引起的。可能由rmi(你使用rmi吗?)或调试器(你有调试器连接吗?)。

Basically all allocations come from an ObjectOutputStream$HandleTable.growEntries method. It looks like the thread the allocations were made on was spun up to handle a network message.
I suspect its caused by jmx itself. Possibly by rmi (do you use rmi?). Or the debugger (do you have a debugger connected?).

这篇关于追踪int []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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