0
.NET Memory Management       Part 1. Basics.
Intro●   Stack & heap●   Heap fragmentation    –   External    –   Internal●   Approaches to memory management    –   C — ...
Value types & reference types●   Value type    –   Primitive built-in (int, bool, ..), enums & user -defined structures   ...
Heaps in .NET●   SOH (Small Object Heap)    –   3 Generations    –   Mark & sweep    –   Compacting●   LOH (Large Object H...
Heap Allocation●   SOH    –   Allocation is in Gen0 heap    –   Consecutive allocation; Next Object Pointer (NOP)    –   F...
Garbage collection : Mark & Sweep●   Mark phase    –   GC roots        ●   Stack        ●   Statics        ●   CPU registe...
Garbage collection : Mark & Sweep●   Sweep phase    –   SOH — with compaction    –   LOH — no compaction    –   Fragmentat...
Gen0 Collection●   Most frequest●   Least expensive●   Objects in Gen0 can    –   Die    –   Be copied to Gen1●   Always l...
Gen1 Collection●   Collects Gen0 and Gen1 heaps●   More expensive than Gen0 collection●   Objects can:    –   Die    –   B...
Gen2 (Full) Collection●   Collects ALL heaps including LOH●   Most expensive GC operation●   Objects can:    –   Die    – ...
Finalization●   Allows to guarantee unmanaged resource    cleanup●   Finalize() and ~ClassName()●   Finalizer rules    –  ...
Links & Books●   Jeffrey Richter, CLR via C#●   Notes on the CLR garbage collector    http://www.vineetgupta.com/2007/01/n...
Upcoming SlideShare
Loading in...5
×

.NET Memory Management - Part 1. Basics

1,408

Published on

Published in: Technology
1 Comment
1 Like
Statistics
Notes
  • It seems slideshare screws up FTP links. Valid link to 'Under the hood of .NET Memory Management' is
    ftp://support.red-gate.com/ebooks/under-the-hood-of-net-memory-management-part1.pdf
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
1,408
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
37
Comments
1
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of ".NET Memory Management - Part 1. Basics"

  1. 1. .NET Memory Management Part 1. Basics.
  2. 2. Intro● Stack & heap● Heap fragmentation – External – Internal● Approaches to memory management – C — malloc / free – C++ — new / delete, smart pointers – Python — GC with reference counting – .NET CLR — GC with mark & sweep
  3. 3. Value types & reference types● Value type – Primitive built-in (int, bool, ..), enums & user -defined structures – Usually lives on stack – Assigned & compared by value● Reference type – Allocated on heap – Assigned & compared by reference – Subject to GC● Boxing / unboxing
  4. 4. Heaps in .NET● SOH (Small Object Heap) – 3 Generations – Mark & sweep – Compacting● LOH (Large Object Heap) – Holds objects >85K – Free space table – Not compacted
  5. 5. Heap Allocation● SOH – Allocation is in Gen0 heap – Consecutive allocation; Next Object Pointer (NOP) – Fast – No internal fragmentation● LOH – Free Space table lookup – Internal fragmentation● Heap expansion – For LOH, heap expansion is preferred to full GC
  6. 6. Garbage collection : Mark & Sweep● Mark phase – GC roots ● Stack ● Statics ● CPU registers ● fReachable – Reachability queue (example) – Islands of isolation
  7. 7. Garbage collection : Mark & Sweep● Sweep phase – SOH — with compaction – LOH — no compaction – Fragmentation considerations
  8. 8. Gen0 Collection● Most frequest● Least expensive● Objects in Gen0 can – Die – Be copied to Gen1● Always leaves Gen0 empty
  9. 9. Gen1 Collection● Collects Gen0 and Gen1 heaps● More expensive than Gen0 collection● Objects can: – Die – Be copied from Gen0 to Gen1 – Be copied from Gen1 to Gen2
  10. 10. Gen2 (Full) Collection● Collects ALL heaps including LOH● Most expensive GC operation● Objects can: – Die – Be copied from Gen0 to Gen1 – Be copied from Gen1 to Gen2 – Stay in Gen2 – Be freed from LOH – Stay in LOH
  11. 11. Finalization● Allows to guarantee unmanaged resource cleanup● Finalize() and ~ClassName()● Finalizer rules – No exceptions – Unmanaged resources only – No use of other finalizable objects
  12. 12. Links & Books● Jeffrey Richter, CLR via C#● Notes on the CLR garbage collector http://www.vineetgupta.com/2007/01/notes-on-the-c● Under the Hood of .NET Memory Management ftp://support.red-gate.com/ebooks/under-the-hood-o● Tesss blog http://blogs.msdn.com/b/tess/archive/2008/04/17/ho●
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×