Garbage Collection (GC) - How and When in .NET?
This is a memory management enabler, a type of de-allocation process, a computing and programming term, referring to the recovery of memory in the heap (see elsewhere), through removal of de-referenced items. It is done and used for program and application stability, reliability, robust performance, improvements , preventing runtime errors, incidents, unexpected events, or ‘bugs’ in the system, code or programming from occurring. For disposal and reclaiming is the motto. Frees up resources and development efforts, energies away from manual allocation and de-allocation of memory.
At its core it is a particular form and process of automatic memory management. A collector, procedure and method, gathering and accumulating objects that will never be accessed or mutated again by an application for example. It traces its roots of origin to John McCarthy (1959) to solve issues with memory management (manual).
For the most part it is the exact opposite of manual memory management, requiring intervention and specification of any, some or all objects to de-allocate and return to the memory system. In the .NET environment it only occurs when needed, specified or called for (GC.Collect), automatic in CLR or Common Language Runtime. For optimal performance stick to the designed, defaults, avoiding unncessary GC.
The operating principles are really simple: chuck what will not ever be used again in the future and reclaim the memory, space and resources associated with it. Here are just some of the application contexts for it: (i) Manual heap allocation search for best/first-fit block of sufficient size and free list maintenance (ii) Garbage collection
To locate, copy reachable objects, read/write barriers for incremental collectors, search for best/first-fit block and free list maintenance for non-moving collectors. Applications in threading, multi-threading, Installing, Configuring and Managing Applications (server applications).
Key Exam Points
- Review the chapters, content and references on Fundamentals, using common reference types, GC.
- For the exam, study practical applications, scenarios, exercises, uses and examples of/for GC tools, processes and applications, that help you to gain a better understanding of this topic
- Take the practice exam, work-labs and related Q&A (multiple choice and application) test sample questions.
This article is based on the 2nd edition of the Microsoft .Net Framework Application Training Kit with the purpose to help 70-536 Exam takers to succeed. I constantly look for ways to improve the content. Please leave a comment about this article or drop me a message if you would like to see changes for this site.