此内存使用模式是否表明我的Java应用程序泄漏了内存? [英] Does this memory usage pattern indicate that my Java application leaks memory?

查看:100
本文介绍了此内存使用模式是否表明我的Java应用程序泄漏了内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java应用程序,等待用户按键然后运行任务。完成后,它会再次返回并等待。我正在使用jvisualvm查看此应用程序的内存配置文件,它显示了一种增加的模式。

I have a Java application that waits for the user to hit a key and then runs a task. Once done, it goes back and waits again. I was looking at memory profile for this application with jvisualvm, and it showed an increasing pattern.

提交的内存大小为16MB。
应用程序启动时使用的内存为2.7 MB,然后使用中间丢弃(垃圾收集)爬升。一旦这个锯齿模式接近16MB,就会出现大幅下降,内存使用量接近4 MB。然而,这个主要的下降点一直在增加。 4MB,6MB,8MB。使用率从未超过16 MB,但整个锯齿模式正在向16 MB的方向攀升。

Committed memory size is 16MB. Used memory, on application startup, was 2.7 MB, and then it climbed with intermediate drops (garbage collection). Once this sawtooth pattern approached close to 16MB, a major drop occurred and the memory usage fell close to 4 MB. This major drop point has been increasing though. 4MB, 6MB, 8MB. The usage never goes beyond 16 MB but the whole sawtooth pattern is on a climb towards 16 MB.

我是否有内存泄漏?

由于这是我第一次发布到StackOverflow,因此没有足够的声誉来发布图片。

Since this is my first time posting to StackOverflow, do not have enough reputation to post an image.

推荐答案

<现代SunOracle JVM使用所谓的世代垃圾收集器:

Modern SunOracle JVMs use what is called a generational garbage collector:


  1. 当收集器运行它时,首先尝试部分收集只释放内存最近被分配

  2. 最近创建的仍处于活动状态的对象获得'提升'

  3. 一旦对象被提升了几次,它将不再

  4. 这些被称为终身的对象只有在需要完整集合时才能清理,以便为程序提供足够的空间。继续运行

  1. When the collector runs it first tries a partial collection only releases memory that was allocated recently
  2. recently created objects that are still active get 'promoted'
  3. Once an object has been promoted a few times, it will no longer get cleaned up by partial collections even after it is ready for collection
  4. These objects, called tenured, are only cleaned up when a full collection becomes necessary in order to make enough room for the program to continue running

所以基本上,你的程序有点坚持不懈地被快速的部分收藏所迷惑,直到JVM决定必须进行全面收集。如果你让它足够长,你应该最终看到完整的集合发生并且使用量下降到你原来的起点。

So basically, bits of your program that stick around long enough to get missed by the fast 'partial' collections will hang around until JVM decides it has to do a full collection. If you let it go long enough you should eventually see the full collection happen and usage drop back down to your original starting point.

如果这种情况从未发生过,你最终会得到一个Out Of Memory异常,那么你可能有内存泄漏:)

If that never happens and you eventually get an Out Of Memory exception, then you probably have a memory leak :)

这篇关于此内存使用模式是否表明我的Java应用程序泄漏了内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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