.net GC (GC roots)小结

reference article: https://www.simple-talk.com/dotnet/.net-framework/understanding-garbage-collection-in-.net/

http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/gc01/index.html#RequiredSoftware 

1. GC roots, 什么可以成为GC roots.

    a). local variable

    b). static variable

    c). If a managed object is passed to an unmanaged COM+ library through interop, then it will also become a GC root with a reference count.


2. objects management in heap:

      young generation(s0, s1), old generation, permanent generation.

      process: marking --> move-->promotion--> compact and recycle

    


3. 两种形式回收堆垃圾: 同步和异步


4. 释放资源的两种方式:

    4.1.  Finalizer (这个事有GC调用的,user想 override它,只有通过 析构函数来完成),但是何时做Finalizer是有GC thread决定的。

     4.2. IDispose,实现IDispose, 可以直接被调用通过Using(....)

注意:其实这里的非托管资源是需要dev自己来管理,你就是不用上面两种方式,自己实现一个方法,在里面去释放资源,也是可以的(只是看着不正规而已)


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值