.NET ਆਪਣੇ ਆਪ garbage collector (GC) ਦੇ ਜ਼ਰੀਏ ਮੈਮੋਰੀ ਦਾ ਪ੍ਰਬੰਧਨ ਕਰਦਾ ਹੈ — ਇਹ managed heap ਉੱਤੇ objects ਨੂੰ allocate ਕਰਦਾ ਹੈ ਅਤੇ ਉਨ੍ਹਾਂ ਨੂੰ reclaim ਕਰਦਾ ਹੈ ਜੋ ਹੁਣ reachable ਨਹੀਂ ਹਨ, ਇਸ ਲਈ ਤੁਹਾਨੂੰ ਮੈਮੋਰੀ ਨੂੰ ਹੱਥੋਂ free ਕਰਨ ਦੀ ਲੋੜ ਨਹੀਂ। GC ਨੂੰ ਸਮਝਣਾ (generational, stack/heap split, ਅਤੇ 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.
