#424 – The Garbage Collector
October 3, 2011 13 Comments
In C#, you don’t explicitly delete heap-based objects. Instead, the CLR will reclaim memory from objects that are no longer used, by running a Garbage Collector.
The garbage collector (GC) can release memory only for managed objects created on the heap. It’s only job is to release memory. It can’t clean up or release other resources, like file handles or database connections.
The GC will typically perform garbage collection when the amount of available physical memory is becoming too low or when the amount of virtual memory consumed by your application is becoming too large.
You can’t predict when garbage collection is going to happen, or even if it’s going to happen, prior to an application terminating.
Pingback: #425 – Nondeterministic Destruction and Object Finalization « 2,000 Things You Should Know About C#
Pingback: #426 – Use a Destructor to Free Unmanaged Resources « 2,000 Things You Should Know About C#
Pingback: #689 – References and Objects « 2,000 Things You Should Know About C#
Pingback: #732 – Destruction vs. Collection « 2,000 Things You Should Know About C#
Pingback: #923 – An Object Isn’t Necessarily Deleted as Soon as Its Dereferenced | 2,000 Things You Should Know About C#
Pingback: #924 – You Shouldn’t Normally Worry about Memory Management | 2,000 Things You Should Know About C#
Pingback: #926 – How Memory Is Allocated for Objects on the Managed Heap | 2,000 Things You Should Know About C#
Pingback: #928 – How Objects Are Removed from the Managed Heap | 2,000 Things You Should Know About C#
Pingback: #931 – Objects with Finalizers Take Longer to Garbage Collect | 2,000 Things You Should Know About C#
Pingback: #937 – Forcing a Garbage Collection | 2,000 Things You Should Know About C#
Pingback: #939 – Not All Objects on Heap Are Promoted to Next GC Generation | 2,000 Things You Should Know About C#
Pingback: #940 – Finalizers Are Called when an Application Shuts Down | 2,000 Things You Should Know About C#
Pingback: Garbage Collection In .NET - Part 2 - Just a tech blog