Memory Analyzer tool(MAT)分析内存泄漏---理解Retained Heap、Shallow Heap、GC Root

时间:2023-01-13 08:40:14

Shallow Heap Size

指对象自身所占用的内存大小,不包含其引用的对象所占的内存大小。

1、数组类型

数组元素对象所占内存的大小总和。

2、非数组类型

对象与它所有的成员变量大小的总和。当然这里面还会包括一些Java语言特性的数据存储单元。

Retained Heap Size

前对象大小+当前对象可直接或间接引用到的对象的大小总和。

(间接引用的含义:A->B->C, C就是间接引用)

换句话说,Retained Size就是当前对象被GC后,从Heap上总共能释放掉的内存。
不过,释放的时候还要排除被GC Roots直接或间接引用的对象。他们暂时不会被被当做Garbage。Memory Analyzer tool(MAT)分析内存泄漏---理解Retained Heap、Shallow Heap、GC Root

GC Roots直接引用了A和B两个对象。

A对象的Retained Size=A对象的Shallow Size
B对象的Retained Size=B对象的Shallow Size + C对象的Shallow Size

这里不包括D对象,因为D对象被GC Roots直接引用。
如果GC Roots不引用D对象呢?

Memory Analyzer tool(MAT)分析内存泄漏---理解Retained Heap、Shallow Heap、GC Root

GC Roots

The so-called GC (Garbage Collector) roots are objects special for
garbage collector. Garbage collector collects those objects that are not
GC roots and are not accessible by references from GC roots.

There are several kinds of GC roots. One object can belong to more than one kind of root. The root kinds are:

  • Class - class loaded by system class loader. Such
    classes can never be unloaded. They can hold objects via static fields.
    Please note that classes loaded by custom class loaders are not roots,
    unless corresponding instances ofjava.lang.Class
    happen to be roots of other kind(s).
  • Thread - live thread
  • Stack Local - local variable or parameter of Java method
  • JNI Local - local variable or parameter of JNI method
  • JNI Global - global JNI reference
  • Monitor Used - objects used as a monitor for synchronization
  • Held by JVM
    - objects held from garbage collection by JVM for its purposes.
    Actually the list of such objects depends on JVM implementation.
    Possible known cases are: the system class loader, a few important
    exception classes which the
    JVM knows about, a few pre-allocated objects for exception handling,
    and custom class loaders when they are in the process of loading
    classes.Unfortunately, JVM provides absolutely no additional detail for such objects. Thus it is up to the analyst
    to decide to which case a certain "Held by JVM" belongs.

If an object is a root, it is specially marked in all views showing
individual objects. For example, the following picture shows a fragment
ofpaths view:

Memory Analyzer tool(MAT)分析内存泄漏---理解Retained Heap、Shallow Heap、GC Root

http://www.yourkit.com/docs/90/help/gc_roots.jsp

Memory Analyzer tool(MAT)分析内存泄漏---理解Retained Heap、Shallow Heap、GC Root的更多相关文章

  1. 使用Memory Analyzer tool(MAT)分析内存泄漏(二)

    转载自:http://www.blogjava.net/rosen/archive/2010/06/13/323522.html 前言的前言 写blog就是好,在大前提下可以想说什么写什么,不像投稿那 ...

  2. 使用Memory Analyzer tool(MAT)分析内存泄漏

    前言的前言 写blog就是好,在大前提下可以想说什么写什么,不像投稿那么字字斟酌.上周末回了趟成都办事,所以本文来迟了.K117从达州经由达成线往成都方向走的时候,发现铁路边有条河,尽管我现在也不知道 ...

  3. 使用Memory Analyzer tool(MAT)分析内存泄漏(一)

    转载自:http://www.blogjava.net/rosen/archive/2010/05/21/321575.html 前言 在平时工作过程中,有时会遇到OutOfMemoryError,我 ...

  4. 性能监控 | MAT分析内存泄漏

    使用MAT分析内存泄漏(二)八周年重印版 - 知乎 .u-safeAreaInset-top { height: constant(safe-area-inset-top) !important; h ...

  5. 【转】如何使用MAT分析内存泄漏

    原文链接:http://www.lightskystreet.com/2015/09/01/mat_usage/ MAT - Memory Analyzer Tool 使用进阶 Sep 1, 2015 ...

  6. [原创]Eclipse Memory Analyzer tool(MAT)工个使用介绍

    [原创]Eclipse Memory Analyzer tool(MAT)工个使用介绍

  7. 使用MAT(Memory Analyzer Tool)工具分析dump文件--转

    原文地址:http://gao-xianglong.iteye.com/blog/2173140?utm_source=tuicool&utm_medium=referral 前言 生产环境中 ...

  8. 使用MAT 分析内存泄漏实战

    在分析前可以阅读下这篇文章,很多内容就都知道了https://www.jianshu.com/p/738b4f3bc44b,下面我来分析上一篇文章内存泄漏的为问题 1.上一篇中已经生成了hprf的文件 ...

  9. Android Studio +MAT 分析内存泄漏实战

    对于内存泄漏,在Android中如果不注意的话,还是很容易出现的,尤其是在Activity中,比较容易出现,下面我就说下自己是如何查找内存泄露的. 首先什么是内存泄漏? 内存泄漏就是一些已经不使用的对 ...

随机推荐

  1. Eclipse Maven Web工程报错:java.lang.ClassNotFoundException: ContextLoaderListener

    原因:打包项目时没有把相关Maven依赖包打到WEB-INF/lib下,正常情况下,会生成lib目录并把工程的所有依赖jar包都部署到该目录下. 解决:右键点击项目--选择Properties,选择D ...

  2. squid代理服务器搭建及配置

    系统环境:CentOS release 6.5 (Final)(最小化安装) 一.安装squid # yum -y install squid 二.编辑配置文件(正向代理) # vim /etc/sq ...

  3. 【制作镜像Win*】特殊配置

    下载disk.config: wget http://10.254.3.75/images/configdrive/disk.config 修改libvirt.xml,更换cdrom为disk.con ...

  4. JavaScript HTML Dom改变HTML

    本人为小白,首次写博客  有不正确的地方望多多指点与见谅!! 一,改变HTML的内容 语法: document.getElementById(id).innerHTML=new HTML: 具体用法: ...

  5. 【尚学堂·Hadoop学习】MapReduce案例1--天气

    案例描述 找出每个月气温最高的2天 数据集 -- :: 34c -- :: 38c -- :: 36c -- :: 32c -- :: 37c -- :: 23c -- :: 41c -- :: 27 ...

  6. Java使用BufferedImage修改图片内容

    1.修改图片的架包 <dependency> <groupId>commons-io</groupId> <artifactId>commons-io& ...

  7. 软件模拟I2C通讯

    I2C协议概述,有相当详细的名词解释: 通信数量受限于地址空间和400Pf总线电容. 所有的数据传输过程中,SDA线的电平变化必须在SCL为低电平时进行,SDA线的电平在SCL线为高电平时要保持稳定. ...

  8. js取整数、取余数

    js取整数.取余数 取整 1.取整 // 丢弃小数部分,保留整数部分 parseInt(5/2) // 2 2.向上取整 // 向上取整,有小数就整数部分加1 Math.ceil(5/2) // 3 ...

  9. 关于ACtion类利用file类型取得上传文件的内容,名字和内容类型

    上面的Action提供了两个属性:uploadFileName和uploadContentType,这个两个属性分别用于封转上传文件的文件名.上传文件的文件类型.Action类直接通过File类型属性 ...

  10. 快速对Mysql添加索引的五个方法

    1.添加PRIMARY KEY(主键索引) mysql>ALTER TABLE `table_name` ADD PRIMARY KEY ( `column` ) 2.添加UNIQUE(唯一索引 ...