.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自己来管理,你就是不用上面两种方式,自己实现一个方法,在里面去释放资源,也是可以的(只是看着不正规而已)


你可能感兴趣的:(.net GC (GC roots)小结)