Your SlideShare is downloading. ×
0
.NET Memory Management - Part 1. Basics
.NET Memory Management - Part 1. Basics
.NET Memory Management - Part 1. Basics
.NET Memory Management - Part 1. Basics
.NET Memory Management - Part 1. Basics
.NET Memory Management - Part 1. Basics
.NET Memory Management - Part 1. Basics
.NET Memory Management - Part 1. Basics
.NET Memory Management - Part 1. Basics
.NET Memory Management - Part 1. Basics
.NET Memory Management - Part 1. Basics
.NET Memory Management - Part 1. Basics
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

.NET Memory Management - Part 1. Basics

1,393

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,393
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
37
Comments
1
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. .NET Memory Management Part 1. Basics.
  • 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. 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. 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. 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. Garbage collection : Mark & Sweep● Mark phase – GC roots ● Stack ● Statics ● CPU registers ● fReachable – Reachability queue (example) – Islands of isolation
  • 7. Garbage collection : Mark & Sweep● Sweep phase – SOH — with compaction – LOH — no compaction – Fragmentation considerations
  • 8. Gen0 Collection● Most frequest● Least expensive● Objects in Gen0 can – Die – Be copied to Gen1● Always leaves Gen0 empty
  • 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. 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. Finalization● Allows to guarantee unmanaged resource cleanup● Finalize() and ~ClassName()● Finalizer rules – No exceptions – Unmanaged resources only – No use of other finalizable objects
  • 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●

×