Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Aug 23, 2022, 8:24 AM EDT
Hello Deepak,
Garbage collection is a low-priority process that serves as an automatic memory manager which manages the allocation and release of memory for the applications. Each time a new object is created, the common language runtime allocates memory for that object from the managed Heap. As long as free memory space is available in the managed Heap,the runtime continues to allocate space for new objects. However, memory is not infinite, and once an application fills the Heap memory space, garbage collection comes into play to free some memory.
When the garbage collector performs a collection, it checks for objects in the managed Heap that are no longer being used by the application and performs the necessary operations to reclaim the memory. Garbage collection will stop all running threads, it will find all objects in the Heap that are not being accessed by the main program and delete them. It will then reorganize all the objects left in the Heap to make space and adjust all the Pointers to these objects in both the Stack and the Heap.
To enforce garbage collection in your code manually, you can run the following command (C#):
Please refer below articles, written very well,
https://www.c-sharpcorner.com/article/garbage-collection-dispose-vs-finalize-and-idisposable-pattern/
https://www.c-sharpcorner.com/uploadfile/puranindia/garbage-collection-in-C-Sharp/
Amit MohantyRank #112 · 20K reputationPosted Aug 23, 2022, 8:32 AM EDT
Vishal YelveRank #178 · 13.6K reputationPosted Aug 23, 2022, 9:16 AM EDT
Uday DodiyaRank #239 · 10.3K reputationPosted Sep 1, 2022, 2:42 AM EDT