一些文章在分析GC时,不可逾越的说到要先从根对象扫描出不可达对象,然后标记那些不可达对象为垃圾。那么源头根对象是什么玩意呢?

几分钟后google到比较可信源是http://stackoverflow.com/questions/8458886/what-is-a-rooted-reference。其解释具体为:

GC roots are not objects in themselves but are instead references to objects. Any object referenced by a GC root will automatically survive the next garbage collection. There are four main kinds of root in .NET:

1,A local variable in a method that is currently running(GC发生时,当前正在执行的方法中那些本地变量) is considered to be a GC root. The objects referenced by these variables can always be accessed immediately by the method they are declared in, and so they must be kept around. The lifetime of these roots can depend on the way the program was built. In debug builds, a local variable lasts for as long as the method is on the stack. In release builds, the JIT is able to look at the program structure to work out the last point within the execution that a variable can be used by the method and will discard it when it is no longer required. This strategy isn’t always used and can be turned off, for example, by running the program in a debugger.

2,Static variables(静态变量) are also always considered GC roots. The objects they reference can be accessed at any time by the class that declared them (or the rest of the program if they are public), so .NET will always keep them around. Variables declared as ‘thread static’ will only last for as long as that thread is running.

3,If a managed object is passed to an unmanaged COM+ library through interop(非托管类似COM+一样通过interop被使用的对象, then it will also become a GC root with a reference count. This is because COM+ doesn’t do garbage collection: It uses, instead, a reference counting system; once the COM+ library finishes with the object by setting the reference count to 0 it ceases to be a GC root and can be collected again.

4,If an object has a finalizer(实现了finalizer接口的对象, it is not immediately removed when the garbage collector decides it is no longer ‘live’. Instead, it becomes a special kind of root until .NET has called the finalizer method. This means that these objects usually require more than one garbage collection to be removed from memory, as they will survive the first time they are found to be unused.

推荐【译】.Net 垃圾回收机制原理(一),其中也提到了finalizer有重活机会。

GC分析中提到的根对象是什么的更多相关文章

  1. 关于Jaccard相似度在竞品分析中的一点思考

    上个月对一个小项目的效果进行改进,时间紧,只有不到一周的时间,所以思考了一下就用了最简单的方法来做,跟大家分享一下(项目场景用的类似的场景) 项目场景:分析一个产品的竞品,譬如app的竞品.网站的竞品 ...

  2. jvm系列:Java GC 分析

    Java GC就是JVM记录仪,书画了JVM各个分区的表演. 什么是 Java GC Java GC(Garbage Collection,垃圾收集,垃圾回收)机制,是Java与C++/C的主要区别之 ...

  3. Jaccard相似度在竞品分析中的应用

    上个月对一个小项目的效果进行改进,时间紧,只有不到一周的时间,所以思考了一下就用了最简单的方法来做,效果针对上一版提升了5%左右,跟大家分享一下(项目场景用的类似的场景) 项目场景:分析一个产品的竞品 ...

  4. jvm系列(九):Java GC 分析

    Java GC就是JVM记录仪,书画了JVM各个分区的表演. 什么是 Java GC Java GC(Garbage Collection,垃圾收集,垃圾回收)机制,是Java与C++/C的主要区别之 ...

  5. JVM-Java GC分析

    如何获取JavaGC日志 用动态命令查看: jstat -gc 1262 2000 20  每隔20秒输入一次日志,总共输入20次 设置GC参数打印出日志 -XX:+PrintGC 输出GC日志 -X ...

  6. 关于gc日志中Desired Survivor的疑问和对象晋升老年代的小结

    问题背景 (下面的所有内容都是根据书上的Serial/Serial Old收集器下的情况) 在<深入理解JVM>一书中的——3.6.3长期存活的对象将进入老年代的介绍中, 一个例子的jvm ...

  7. 【GC分析】Java GC日志查看

    Java中的GC有哪几种类型? 参数 描述 UseSerialGC 虚拟机运行在Client模式的默认值,打开此开关参数后, 使用Serial+Serial Old收集器组合进行垃圾收集. UsePa ...

  8. jvm系列(五):Java GC 分析

    Java GC就是JVM记录仪,书画了JVM各个分区的表演. 什么是 Java GC Java GC(Garbage Collection,垃圾收集,垃圾回收)机制,是Java与C++/C的主要区别之 ...

  9. 一次高IO下的GC分析之旅

    一次高IO下的GC分析之旅 编码前线 关注 2018.12.21 00:06 字数 597 阅读 45评论 0喜欢 0 起因:收到GC STW报警 [监控系统]Total time for which ...

随机推荐

  1. react组件生命

    组件的生命周期主要由三个部分组成: Mounting:组件正在被插入DOM中 Updating:如果DOM需要更新,组件正在被重新渲染 Unmounting:组件从DOM中移除 React提供了方法, ...

  2. 【汇总】C#数据类型及转换

    13.C# 16进制与字符串.字节数组之间的转换 https://www.cnblogs.com/seventeen/archive/2009/10/29/1591936.html C# 对象.文件与 ...

  3. CentOS 修改源为163和指定epel源和docker安装

    首先备份/etc/yum.repos.d/CentOS-Base.repo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-B ...

  4. 超越Google,腾讯推出自研图片编码格式TPG

    近日,记者从国家知识产权局了解到,腾讯公司正式向国家知识产权局提交了一份关于图片编码技术的专利申请.此项专利被命名为TPG(Tiny Portable Graphics),在数据上TPG图片格式产生的 ...

  5. gridView删除提示框

    实现方法: 双击GridView的OnRowDataBound事件: 在后台的GridView1_RowDataBound()方法添加代码,最后代码如下所示: protected void GridV ...

  6. python:随机数 random

    #随机数 import random print(random.randint(10,12))#生成10-12之间的整数 print(random.uniform(10,12))#生成10-12之间的 ...

  7. ROS 禁止公网暴力破解SSH FTP

    最简单的彻底禁止公网访问SSH FTP端口 1 2 /ip firewall filter add chain=input protocol=tcp dst-port=21-22 src-addres ...

  8. 快速上手Runtime(一)之消息机制

    Runtime简介 Runtime简称运行时.OC就是运行时机制,也就是在运行时候的一些机制,其中最主要的是消息机制. 对于C语言,函数的调用在编译的时候会决定调用哪个函数. 对于OC的函数,属于动态 ...

  9. 02- 画文字和图片-------------之前写的那个微博项目,可以试试用画图片的方式来处理,这样应该比UILabel 代码少点,一会试试

    1.画图片 - (void)drawRect:(CGRect)rect { // Drawing code UIImage *image = [UIImage imageNamed:@"pa ...

  10. SqlServer 分区视图实现水平分表

    我们都知道在数据库数据量较多的时候,可数据进行水平扩展,如分库,分区,分表(也叫分区)等.对于分表的一个方案,就是使用分区视图实现. 分区视图允许将大型表中的数据拆分成较小的成员表.根据其中一列中的数 ...