#424 – The Garbage Collector

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.

Advertisements

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

13 Responses to #424 – The Garbage Collector

  1. Pingback: #425 – Nondeterministic Destruction and Object Finalization « 2,000 Things You Should Know About C#

  2. Pingback: #426 – Use a Destructor to Free Unmanaged Resources « 2,000 Things You Should Know About C#

  3. Pingback: #689 – References and Objects « 2,000 Things You Should Know About C#

  4. Pingback: #732 – Destruction vs. Collection « 2,000 Things You Should Know About C#

  5. Pingback: #923 – An Object Isn’t Necessarily Deleted as Soon as Its Dereferenced | 2,000 Things You Should Know About C#

  6. Pingback: #924 – You Shouldn’t Normally Worry about Memory Management | 2,000 Things You Should Know About C#

  7. Pingback: #926 – How Memory Is Allocated for Objects on the Managed Heap | 2,000 Things You Should Know About C#

  8. Pingback: #928 – How Objects Are Removed from the Managed Heap | 2,000 Things You Should Know About C#

  9. Pingback: #931 – Objects with Finalizers Take Longer to Garbage Collect | 2,000 Things You Should Know About C#

  10. Pingback: #937 – Forcing a Garbage Collection | 2,000 Things You Should Know About C#

  11. Pingback: #939 – Not All Objects on Heap Are Promoted to Next GC Generation | 2,000 Things You Should Know About C#

  12. Pingback: #940 – Finalizers Are Called when an Application Shuts Down | 2,000 Things You Should Know About C#

  13. Pingback: Garbage Collection In .NET - Part 2 - Just a tech blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: