首页 技术 正文
技术 2022年11月6日
0 收藏 909 点赞 1,128 浏览 1743 个字

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

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,556
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,406
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898