• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
.NET Memory Management - Part 1. Basics
 

.NET Memory Management - Part 1. Basics

on

  • 1,543 views

 

Statistics

Views

Total Views
1,543
Views on SlideShare
1,543
Embed Views
0

Actions

Likes
0
Downloads
22
Comments
1

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

11 of 1 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • 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
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    .NET Memory Management - Part 1. Basics .NET Memory Management - Part 1. Basics Presentation Transcript

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