(转)GC ROOTS
还是英文的技术博客更给力,更清楚,本人懒,没有翻译。
In your specific example, in any managed environment, Person is not a GC root; the GC root is the thingwhich holds the reference to Person. The difference is subtle, but important in the context of this question. Although my answer is specific to Java it is in general correct for any managed language. Your last paragraph is actually correct, but conflicts with the example given.
The GC (Garbage Collector) roots are objects special for garbage collector. The 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 of java.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 you think of the objects in memory as a tree, the "roots" would be the root nodes - every object immediately accessible by your program.
There are four objects; a person, a red car, its engine and horn. Draw the reference graph:
And you'll end up with Since Consider, however, if the following is run after a while:
And redraw the graph:
Now the So it's really a matter of taking every starting point (every local variable, globals, statics, everything in other threads and stack frames) — every root — and recursively following all the references to make up a list of all the "live" objects: objects which are in use and unsuitable for deletion. Everything else is garbage, waiting to be collected. |
(转)GC ROOTS的更多相关文章
- gc roots 垃圾回收
gc roots包括以下几个: 虚拟机栈(栈桢中的本地变量表)中的引用对象 方法区中的类静态属性引用的对象 方法区中的常量引用的对象 本地方法栈中JNI(即native方法)的引用的对象 java,c ...
- 枚举GC Roots的实现
枚举根节点 从可达性分析中从GC Roots节点找引用链这个操作为例,可作为GC Roots的节点主要在全局性的引用(例如常量或类静态属性)与执行上下文(例如栈帧中的本地变量表)中,现在很多应用仅仅方 ...
- GC roots 总结
previous content next GC roots The so-called GC (Garbage Collector) roots are objects ...
- GC roots
1.虚拟机栈(本地变量表)引用的对象 2.方法区静态属性引用的对象 3.方法区常量引用的对象 4.本地方法栈JNI(一般指naive方法)中引用的对象 常说的GC(Garbage Collecto ...
- JVM总括二-垃圾回收:GC Roots、回收算法、回收器
JVM总括二-垃圾回收:GC Roots.回收算法.回收器 目录:JVM总括:目录 一.判断对象是否存活 为了判断对象是否存活引入GC Roots,如果一个对象与GC Roots没有直接或间接的引用关 ...
- 【JVM底层策略 一】GC roots如何判断对象不可达
查找内存中不再使用的对象 引用计数法 引用计数法就是如果一个对象没有被任何引用指向,则可视之为垃圾.这种方法的缺点就是不能检测到环的存在. 2.根搜索算法 根搜索算法的基本思路就是通过一系列名为”GC ...
- JVM 垃圾回收GC Roots Tracing
1.跟搜索算法: JVM中对内存进行回收时,需要判断对象是否仍在使用中,可以通过GC Roots Tracing辨别. 定义: 通过一系列名为”GCRoots”的对象作为起始点,从这个节点向下搜索,搜 ...
- 什么是GC Roots
GC Root 2012年11月28日 ⁄ 综合 ⁄ 共 625字 ⁄ 字号 小 中 大 ⁄ 评论关闭 常说的GC(Garbage Collector) roots,特指的是垃圾收集器(Ga ...
- GC Roots的理解以及如何判断一个对象为“垃圾”
http://blog.csdn.net/Great_Smile/article/details/49935307 这篇博客中讲解了哪些可以作为GC Roots以及如何判断一个对象为垃圾
- Java 虚拟机枚举 GC Roots 解析
JVM 堆内存模型镇楼. 读<深入理解 Java 虚拟机>第三章GC算法,关于 GC Roots 枚举的段落没说透彻,理解上遇到困惑.因此对这点进行扩展并记录,发现国内各种博客写来写去都是 ...
随机推荐
- 今日份Java
package util; import java.sql.*; public class DBUtil { static String url = "jdbc:mysql://localh ...
- adworld python-trade | python反编译
附件是.pyc格式的文件. Python程序中,原始程序代码存储在.py文件里,而Python会在执行.py文件的时候,会将.py形式的程序编译成中间式文件(byte-compiled)的.pyc文件 ...
- 安装Mailx到CentOS(YUM)
运行环境 系统版本:CentOS Linux release 7.3.1611 (Core) 软件版本:无 硬件版本:无 安装过程 1.配置网络 [root@localhost ~]# vi /etc ...
- C语言二级选择题考点汇总-数据结构与算法-【考点一】 什么是算法
1.算法及其基本特征 算法是指对方案的准确描述,是解决问题的执行步骤. 算法不等于数学上的计算方法,也不等于程序.程序是算法的载体. 算法的基本特征如下: (1)可行性:步骤可实现,执行结果可达到 ...
- 框架里增加.env文件的作用
在实际开发中我们常常遇到这样的问题,就是开发地点不固定,这就造成了我们需要频繁的更改数据库配置,给开发工作造成了麻烦,.env环境文件的出现解决了这个麻烦,我们只需要在不同的工作地点配置好.env文件 ...
- CentOS7防火墙设置常用命令
目录 开/关/重启防火墙 查看所有开启的端口号 CentOS7环境下防火墙常用命令 开/关/重启防火墙 查看防火墙状态 firewall-cmd --state 启动防火墙 systemctl sta ...
- C# IO流与文件读写学习笔记
本笔记摘抄自:https://www.cnblogs.com/liyangLife/p/4797583.html,记录一下学习过程以备后续查用. 一.文件系统 1.1文件系统类的介绍 文件操作类大都在 ...
- 关于牛客网C语言结构体位域(bit-fields)的一道题
题目链接地址: https://www.nowcoder.com/questionTerminal/f4e20747a2dd4649bac0c028daa234f4 来源:牛客网 低地址字节 Byte ...
- flex 属性
一.flex-direction(元素排列方向) 1.flex-direction:row://从左到右排列 2.flex-direction:column://从上往下排列 二.flex-wrap( ...
- java开发就业招聘管理系统 ssh源码
开发环境: Windows操作系统开发工具: MyEclipse+Jdk+Tomcat+MySql数据库 此项目分为 用户 企业 管理员三种角色 运行效果图