Java进程内存无限期增长.内存泄漏? [英] Java process memory growing indefinitely. Memory leak?

查看:810
本文介绍了Java进程内存无限期增长.内存泄漏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在Solaris 10上运行了一个Java进程,可为大约200-300个并发用户提供服务.管理员报告说,进程使用的内存会随着时间的推移而显着增加.几天之内达到2GB,并且永不停止增长.

We have a java process running on Solaris 10 serving about 200-300 concurrent users. The administrators have reported that memory used by process increases significantly over time. It reaches 2GB in few days and never stops growing.

我们已经转储了堆并使用Eclipse Memory Profiler对其进行了分析,但在那里看不到任何异常.堆的大小很小.

We have dumped the heap and analysed it using Eclipse Memory Profiler, but weren't able to see anything out of the ordinary there. The heap size was very small.

在向我们的应用程序添加内存状态日志后,我们发现管理员使用的"top"实用程序报告的内存使用情况与MemoryMXBean和Runtime库报告的使用情况之间存在差异.

After adding memory stat logging, to our application we have found discrepancy between memory usage reported by "top" utility, used by the administrator, and the usage reported by MemoryMXBean and Runtime libraries.

这是两者的输出.

Memory usage information 

From the Runtime library
Free memory: 381MB
Allocated memory: 74MB
Max memory: 456MB
Total free memory: 381MB

From the MemoryMXBean library.
Heap Committed: 136MB
Heap Init: 64MB
Heap Used: 74MB
Heap Max: 456MB
Non Heap Committed: 73MB
Non Heap Init: 4MB
Non Heap Used: 72MB

Current idle threads: 4
Current total threads: 13
Current busy threads: 9
Current queue size: 0
Max threads: 200
Min threads: 8
Idle Timeout: 60000

  PID USERNAME NLWP PRI NICE  SIZE   RES STATE    TIME   CPU COMMAND
99802 axuser   115   59    0 2037M 1471M sleep  503:46 0.14% java

怎么可能? top命令报告了更多用法.我期望RES应该接近堆+非堆.

How can this be? top command reports so much more usage. I was expecting that RES should be close to heap+non-heap.

pmap -x会报告堆中的大部分内存:

pmap -x , however, reports most of the memory in the heap:

Address     Kbytes       RSS       Anon     Locked Mode   Mapped File
*102000         56         56         56       - rwx----    [ heap ]
*110000       3008       3008       2752       - rwx----    [ heap ]
*400000    1622016    1621056    1167568       - rwx----    [ heap ]
*000000      45056      45056      45056       - rw-----    [ anon ]

有人可以阐明这一点吗?我完全迷路了.

Can anyone please shed some light on this? I'm completely lost.

谢谢.

更新

这在Linux上似乎不是问题.

This does not appear to be an issue on Linux.

此外,根据彼得·劳瑞(Peter Lawrey)的回答,pmap报告的堆"是本机堆,而不是Java堆.

Also, based on the Peter Lawrey's response the "heap" reported by pmap is native heap not Java heap.

推荐答案

在垃圾回收的环境中,保留未使用的指针将导致泄漏失败",并阻止GC进行其工作.真的很简单 意外地使指针停在附近.

In garbage collected environments, holding on to unused pointers amounts to "failure to leak" and prevents the GC from doing its job. It's really easy to accidentally keep pointers around.

一个常见的罪魁祸首是哈希表.另一个是数组或向量 逻辑清除(通过将重用索引设置为0),但实际 数组的内容(在使用索引上方)仍指向某物.

A common culprit is hashtables. Another is arrays or vectors which are logically cleared (by setting the reuse index to 0) but where the actual contents of the array (above the use index) is still pointing to something.

这篇关于Java进程内存无限期增长.内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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