.NET manages memory automatically via a garbage collector (GC) — it allocates objects on the managed heap and reclaims those no longer reachable, so you don't manually free memory. Understanding the GC (generational, the stack/heap split, and IDisposable) matters for performance and correctness.
Stack vs heap
Stack → value types (locals), method frames; fast, automatically freed when scope ends.
Heap → reference type objects (class instances); managed by the GC.
A reference variable lives on the stack but points to its object on the heap.
