The Garbage Collector. It’s a wonderful “invention” which bring happiness to developers working with managed code. Have you ever used malloc, new, delete… ? Early C++ programmers can tell about how tedious it can be to allocate and de-allocate memory every time you use them in un-managed programs. The kind of problems that can occur are not fun at all.
Did you know the first version of the Garbage Collector (GC) at Microsoft was done for JScript and VBScript ?
Did you know GC was initially coded in Lisp ?
Did you know GC operates in two phases when doing collection ?
Did you know GC works in conjunction with the Execution Engine (EE) or CLR when identifying the memory spots to be released during collection ?
Did you why, even if it’s possible to manually run the GC, this is non-recommended practice ?
Did you know who Patrick Dussud is ?
Explicit calls to GC.Collect() are used in some resource management problems. Sometimes, you have previous resources, like database connections that need to be released. In order to convince the GC to start, GC.Collect is used. As a programmer, you don’t have to do that manually. This is handled automatically.
If you replied no to some of those questions, you might want to take a look at the Channel9 video posted below. Doing so, you will about what GC is, how it works, why it does what it does, how it evolved and so on.
Patrick is a Distinguised Engineer and has been working on automatic object lifetime management systems for many years (that’s one way to think about a GC – automatic object lifetime manager). Ever wonder what happens to running .NET code when a garbage collection occurs? Why did Patrick decide to allow programmers to invoke a garbage collection programmatically?
Enjoy the video. Have fun. It’s good to go to the basics and try to understand the plumbing. Don’t just stay on top of the iceberg without paying attention to the internal mechanics. There is so much to learn there. Click the image below to access the video.