.NET Memory Management - Part 2. Advanced topics and tools
.NET Memory Management Part 2. Advanced topics and tools.
More on generational GC● Problem statement – Older objects can reference newer ones● Compiler generated code to keep track – Memory barrier● Card table – Internal bit table that marks dirty old object regions
GCHandles● System.Runtime.InteropServices.GCHandle● Additional GC Roots from GCHandle table● Kinds – Normal – Weak – WeakTrackResurrection – Pinned
Segments● How managed heaps work with physical memory● Ephemeral segment – Keeps Gen0 and Gen1● Segments can be returned to OS● Segments and LOH – Free memory in LOH is not swapped
More CLR heaps● Loader heap – CLR type system – GC Roots from static fields – Size depends on assembly count● JIT heap – JIT-ted code is stored here
GC Flavors● Workstation GC. Can be: – Stop-the-world – Concurrent – Background (.NET 4.0)● Server GC
Tools: Performance counters● .NET CLR Memory – % Time in GC – Bytes in all heaps – Total committed bytes – Heap size counters ● Gen0 – #GenX Collections ● 10x rule● .NET CLR Loading – Bytes in loader heap● Case study● http://msdn.microsoft.com/en-us/library/x2tyfybc.aspx