Course · 32 lessons

Memory & Garbage Collection

Trace ownership, understand CoreCLR GC, and investigate memory across managed runtimes.

  1. Reachability and object graphs

    Follow references from an owner instead of equating a missing variable name with reclaimed memory.

    Reachability · 18 min
  2. Allocation, aliases, and value copies

    Distinguish creating an object from copying a reference or copying a struct value.

    Reachability · 18 min
  3. Closures retain captured state

    Follow a delegate through the variables it captures and the owner that stores it.

    Reachability · 18 min
  4. Events and listener retention

    End an event subscription when the listening component no longer needs updates.

    Reachability · 18 min
  5. CoreCLR generations and promotion

    Understand CoreCLR’s lifetime heuristic without imposing its generation model on every C# runtime.

    Runtime architecture · 18 min
  6. CoreCLR heap regions: SOH, LOH, and POH

    Separate payload size from runtime-specific heap organization and public generation reporting.

    Runtime architecture · 18 min
  7. Fragmentation and free space

    Distinguish releasing ownership from measuring contiguous free regions in a collector.

    Runtime architecture · 18 min
  8. Pinning and the pinned-object heap boundary

    Use a bounded pinned handle without confusing it with a POH migration or an operating-system call.

    Runtime architecture · 18 min
  9. Finalization versus deterministic disposal

    End owned resource work explicitly without pretending that Dispose frees managed object memory.

    Ownership patterns · 18 min
  10. SafeHandle ownership without native calls

    Observe SafeHandle’s explicit cleanup protocol using a clearly labeled managed test token.

    Ownership patterns · 18 min
  11. Weak references are optional access

    Use TryGetTarget without treating a weak reference as a guaranteed cache or cleanup signal.

    Ownership patterns · 18 min
  12. Static caches and explicit lifetime policies

    Treat a static cache as a long-lived owner, not as automatically disposable temporary storage.

    Ownership patterns · 18 min
  13. Boxing and reference identity

    Observe boxed value semantics before making allocation claims about generic or object-based APIs.

    Ownership patterns · 18 min
  14. ArrayPool leases and clearing policy

    Use only the initialized logical prefix and return a rented buffer exactly once.

    Ownership patterns · 18 min
  15. Collection capacity and reuse

    Separate current membership from reserved backing storage and retained element references.

    Ownership patterns · 18 min
  16. Measuring allocated bytes responsibly

    Treat allocation deltas as target-specific observations rather than retained-memory totals.

    Investigation · 18 min
  17. A profiling plan starts with a reproducible workload

    Instrument logical work before selecting target-specific memory tools.

    Investigation · 18 min
  18. What GC.Collect cannot fix

    A requested collection does not make a strongly reachable object disappear.

    Investigation · 18 min
  19. CoreCLR, Mono/WebAssembly, and Unity

    Record the execution profile before applying collector diagrams, measurements, or tooling assumptions.

    Investigation · 18 min
  20. A complete memory investigation workflow

    Prove lifecycle behavior, identify retaining owners, and measure the actual target before claiming a fix.

    Investigation · 18 min
  21. Minor collections and old-to-young references

    Trace a write barrier, distinguish a collection set from the full graph, and test an old owner with a young child.

    Advanced Memory Investigations · 18 min
  22. Retaining paths, cycles and dominators

    Build an ownership graph, separate shallow from retained size, and identify independent roots.

    Advanced Memory Investigations · 18 min
  23. Async, callbacks and cancellation ownership

    Follow captured state through pending work and end cancellation registrations at their real lifetime boundary.

    Advanced Memory Investigations · 18 min
  24. LOH allocation, fragmentation and compaction evidence

    Separate payload length, object size, free gaps and committed memory before tuning large allocations.

    Advanced Memory Investigations · 18 min
  25. Pinned lifetimes and the pinned-object heap

    Separate strong ownership, pin duration, POH allocation and native pointer validity.

    Advanced Memory Investigations · 18 min
  26. Finalizer queues, resurrection and disposal

    Separate eligibility, finalizer execution, graph retention and deterministic resource release.

    Advanced Memory Investigations · 18 min
  27. Span, Memory and hidden backing-store retention

    Expose the difference between a view, a copy, an owner and a valid buffer lease.

    Advanced Memory Investigations · 18 min
  28. Pool leases, clearing and exception paths

    Return rented buffers exactly once, expose logical lengths and include retained pool capacity in the budget.

    Advanced Memory Investigations · 18 min
  29. Measure allocations without confusing live memory

    Warm the code, keep the measured work synchronous, and separate allocation throughput from retention.

    Advanced Memory Investigations · 18 min
  30. Backpressure is a memory ownership policy

    Budget active and queued payloads, acquire admission before allocating and release every cancelled lease.

    Advanced Memory Investigations · 18 min
  31. GC modes, DATAS and container budgets

    Read effective runtime settings and distinguish a managed heap limit from a whole-process memory limit.

    Advanced Memory Investigations · 18 min
  32. A complete memory incident investigation

    Correlate counters, surviving types, retaining paths, native memory and latency before choosing a fix.

    Advanced Memory Investigations · 18 min