(转)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 枚举的段落没说透彻,理解上遇到困惑.因此对这点进行扩展并记录,发现国内各种博客写来写去都是 ...
随机推荐
- IDEA安装Flutter遇到的坑
环境: ①IDEA2019.3.3 ②JAVA12 ③Android-SDK29.0.3 ④Flutter1.14.6 ⑤WINDOWS10.0.18363.657 ⑥AL10实体机,Android8 ...
- 吴裕雄--天生自然HADOOP操作实验学习笔记:mapreduce代码编程
实验目的 深入了解mapreduce的底层 了解IDEA的使用 学会通过本地和集群环境提交程序 实验原理 1.回忆mapreduce模型 前面进行了很多基础工作,本次实验是使用mapreduce的AP ...
- Spring MVC 定时任务注解说明
一.注解说明. Spring 自带的定时任务执行@Scheduled注解,可以定时的.周期性的执行一些任务.查看@Scheduled的注解可以看到有以下三种: 1.1 String cron() de ...
- PHP0006:PHP基础--函数2
如果php后面没有任何html代码就可以 删掉后面的 ?> 符号 file_put_content 是覆盖写入文件信息
- python笔记09
今日内容 三元运算 函数 内容详细 三元运算(三目运算) v = 前面 if 条件 else 后面 if 条件: v = '前面' else: v = '后面' # 让用户输入值,如果值是整数,则转换 ...
- CodeForces - 1109A
#include<cstdio> #include<map> #include<iostream> #include<algorithm> using ...
- win10修改jupyter notebook默认路径
安装anaconda3 ,因此自带jupyter notebook 发送到jupyter notebook到桌面快捷方式 右击属性,将目标的%USERPROFILE%,修该为自己需要的路径 起始位置修 ...
- 金蝶云星空BOS开发视频分享
https://vip.kingdee.com/school/implementCourseOnline
- .NetCore学习笔记:一、UnitOfWork工作单元
Maintains a list of objects affected by a business transaction and coordinates the writing out of ch ...
- jQuery---手风琴案例
手风琴案例 <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF ...