1 / 19

GC Algorithm inside .NET Luo Bingqiao 5/22/2009

GC Algorithm inside .NET Luo Bingqiao 5/22/2009. Agenda. 经典基本垃圾回收算法 CLR 中垃圾回收算法介绍 SSCLI 中 Garbage Collection 源码分析. 经典基本垃圾回收算法. Reference Counting 算法 Mark-Sweep 与 Mark-Sweep-Compact 算法 Copying 算法. Reference Counting 算法. Storing the Number of reference, Pointers, and resource such

calvin
Download Presentation

GC Algorithm inside .NET Luo Bingqiao 5/22/2009

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. GC Algorithm inside .NET Luo Bingqiao 5/22/2009

  2. Agenda 经典基本垃圾回收算法 CLR中垃圾回收算法介绍 SSCLI中Garbage Collection源码分析

  3. 经典基本垃圾回收算法 Reference Counting算法 Mark-Sweep与Mark-Sweep-Compact算法 Copying 算法

  4. Reference Counting算法 • Storing the Number of reference, Pointers, and resource such • as an Object or Memory block. • Simple reference counting • Deferred reference counting • One-bit reference counting • Weighted reference counting

  5. Reference Counting算法 • Advantages and Disadvantages • Reclaim objects promptly • Difficult to resolve circular references • Examples of Use: • COM, Cocoa, Delphi, PHP, Python

  6. Mark-Sweep • Initially, allocate objects on the heap sequentially • At some stage, mark the objects that are dead and can be removed • Free the dead object slots at some stage

  7. Mark-Sweep • Advantages and Disadvantages • Minimal house-keeping overhead (just one free list) • Every allocation request requires a walk thru the free list, makes allocations slow • Heap fragmentation • Examples of Use: • C Runtime Heap, .NET Micro Framework

  8. Copy and Collect • Keep two heaps • Allocate only from one heap • When collection is triggered on the heap, copy all alive objects to the second heap • Switch the roles of heaps

  9. Copy and Collect • Advantages and Disadvantages • Conceptual Simplicity • Copy operation needs to be done for all objects • Blocks a lot of memory unnecessarily

  10. What happens in CLR and JVM?

  11. GC Algorithms in advanced OO language VMS • Mark Sweep Compact / Train algorithm • Generational incremental Collector • Large Object Heap • Segments • Finalization in CLR • Weak References • Pinning • Object Layout

  12. Heap Organization Heap organization for the train algorithm.

  13. Overall of GC Algorithm

  14. Mark Phase:

  15. Mark Phase • Separate the live objects from dead objects for the • generation being collected. • All small dead objects have their Mark bit set, and if required Pin bit also set • Finalizable objects are put on the FReachable queue • Weak pointers to dead objects are nulled • All large dead objects are put on the FreeList

  16. Sweep Phase: Put all dead objects on a free list

  17. Managed Heap after Compact:

  18. Finalization Internals

  19. More Information • External ISMM forum <<Garbage Collection>>, Algorithms for automatic Dynamic Memory managements • Email lbq1221119@hotmail.com

More Related