如何处理Java EE中的内存泄漏? [英] How to handle memory leaks in Java EE?
问题描述
当我在网上找到某个地方时,下列项目可能导致内存泄漏。例如:
- ResultSets和Statement对象
- 数据列表
- 集合
- 静态变量和类
- 单例
- HttpSession和HttpRequest
我的JSF应用程序中的托管bean大多是 @ViewScoped
,所以我认为在离开视图后, GC有足够的信息来释放数据列表,对象等。但它没有或不完整:
我只是手动关闭休眠会话(最终使用),但仅此而已。我从GC期望的其他事情。
你可以告诉我,如何找到哪些具体的物体停留在哪里? 在内存中?
As I've found somewhere on web, following items can lead to memory leaks. For example:
- ResultSets and Statement objects
- DataLists
- Collections
- Static variables and classes
- Singletons
- HttpSession and HttpRequest
Managed beans in my JSF application are mostly @ViewScoped
, so I thought that after leaving the view, GC has enough informations to release datalists, objects, and so on. But it hasn't or not completelly:
I'm just closing hibernate sessions manually (using finally), but that's all. The rest of things I've expected from GC.
Could you tell me,
- how to find which concrete objects are staying in memory?
- how to release objects after leaving a view manually? something like destructor..?
- what are the best practices in handle memory leaks?
JHat, Eclipse MAT can be helpful. Even, JConsole gives enough clues about memory leaks -- or at least what's hogging all of your RAM.
这篇关于如何处理Java EE中的内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!