当不是所有使用的堆都可以从线程访问时,查找Java内存泄漏 [英] Finding Java memory leak when not all used heap is reachable from threads

查看:153
本文介绍了当不是所有使用的堆都可以从线程访问时,查找Java内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个大量的基于Java的系统中的潜在内存泄漏(或至少是内存浪费)。 JVM运行的最大堆大小为5 GB,而2-3GB的堆用量是应用程序的预期基准线。 (可能会有更高的峰值)



在我正在调查堆的堆载情况下,已经填满了。使用Eclipse MemoryAnalyzer工具分析堆转储显示(不奇怪)堆完全耗尽。



MAT显示2个潜在的泄漏候选者保留2.5GB:java.lang.Thread和系统中的一个域对象,该对象在系统的事务处理过程中被广泛使用。然而,所有这些域对象(不奇怪)可以从Thread实例访问。毕竟这些线程正在处理事务。因此,归因于java.lang.Thread的2.5 GB几乎完全是由这些域对象引起的。



列出所有java.lang.Thread实例的对象树,并对所有线程的保留堆进行求和,得到2.5 GB的保留堆。 p>

如果从java.lang.Thread的实例无法访问堆栈,我应该在哪里找到需要的其他2.5 GB?
- 终结者队列中没有什么
- 没有大量不可达到的对象等待GC



我认为另一种方法问题是:我如何找到从java.lang.Thread实例无法访问的所有对象?也许是一个OQL查询?,另一个问题是:什么样的对象不可从一个实例java.lang.Thread其他然后在Finalizer中的对象Queue和未引用的对象等待GC?

解决方案

我也面临着这个问题内存泄漏在我们的网站上,

使用 yourkit java profiler 它提供了大量的信息,并具有能力,您可以拥有更广泛的图像,所有的记忆都被利用。

你可以找到一个伟大的教程查找Java内存泄漏与a bove工具。



您的问题,


没有什么样的对象可以从java.lang.Thread的实例访问另一个,然后在Finalizer中的对象Queue和未引用的对象等待GC?


有四个


  1. 强大的可达性,可以通过实时对象引用直接访问的对象

  2. 弱/软可达,弱对象/与其相关联的软引用

  3. 待定终止,待完成的对象以及可通过终结者队列到达的对象

  4. 无法访问这些对象,从GC根目录无法访问,但尚未收集

除了这些JVM还使用您可以在IBM上找到其信息的本机内存 JVM使用的堆和本地内存感谢内存,根据YourKit的 JVM内存结构具有非堆内存,根据他们的定义是


此外,JVM还具有除堆之外的内存,称为非堆内存。它在JVM启动时创建,并存储每个类的结构,例如运行时常量池,字段和方法数据,以及方法和构造函数的代码以及interned Strings。



I am looking into a potential memory leak (or at least memory waste) in a largish Java based system. The JVM is running with a maximum heap size of 5 GB and 2-3GB heap usage is an expected base line for the application. (There can be peaks that are higher)

In an overload scenario which I am investigating the heap gets filled up. Analyzing the a heap-dump with the "Eclipse MemoryAnalyzer Tool" shows (no surprise) that the heap is entirely used up.

MAT shows 2 potential leak candidates, both roughly retaining 2.5GB: java.lang.Thread and a domain object from the system which is used extensively during transaction processing in the system. All these domain objects are however (no surprise) reachable from the Thread instances. Those threads are processing the transactions, after all. Thus, the 2.5 GB attributed to java.lang.Thread is almost entirely caused by those domain objects. No surprise here.

Listing the object tree of all java.lang.Thread instances and summing up the retained heap of all threads results in 2.5 GB of retained heap.

Where should I look for the other 2.5 GB that are needed to fill up the heap, if they are not reachable from an instance of java.lang.Thread? - There is nothing in the finalizer queue - There is not a significant amount of unreachable objects pending GC

I think another way to put this question is: "How do I find all objects that are not reachable from an instance of java.lang.Thread? Maybe an OQL query?, and the other question: "What kind of Objects are there that are not reachable from an instance of java.lang.Thread other then Objects in the Finalizer Queue and unreferenced objects pending GC?"

解决方案

I too faced the problem with memory leaks at our site,
Use yourkit java profiler which provide lots of information and with its ability you can have a wider image where all the memory is being utilized.
You can find a great tutorial Find Java Memory Leaks with the above tool.

Your question,

"What kind of Objects are there that are not reachable from an instance of java.lang.Thread other then Objects in the Finalizer Queue and unreferenced objects pending GC?"

There are four kinds of object,

  1. Strong reachable, objects that can be reached directly via references from live objects
  2. Weak/Soft reachable, objects that are having weak/Soft reference associated with them
  3. Pending Finalization, objects that are pending for finalization and whose reference can be reached through finalizer queue
  4. Unreachable these are objects that are unreachable from GC roots, but not yet collected

Besides these JVM also uses Native memory whose information you can find on IBM Heap and native memory use by the JVM and Thanks for the memory and according to YourKit the JVM Memory Structure has Non-Heap Memory whose definition according to them is

Also, the JVM has memory other than the heap, referred to as non-heap memory. It is created at the JVM startup and stores per-class structures such as runtime constant pool, field and method data, and the code for methods and constructors, as well as interned Strings.

这篇关于当不是所有使用的堆都可以从线程访问时,查找Java内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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