.NET memory को garbage collector (GC) के माध्यम से स्वचालित रूप से प्रबंधित करता है — यह objects को managed heap पर allocate करता है और उन्हें पुनः प्राप्त करता है जो अब reachable नहीं हैं, इसलिए आपको manually memory free नहीं करनी पड़ती। GC को समझना (generational, stack/heap विभाजन, और IDisposable) performance और correctness के लिए मायने रखता है।
stack बनाम 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.
