Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
One of the benefits of .NET’s managed execution model is that the
runtime can automate most of your application’s memory management. I have
shown numerous examples that create objects with the new keyword, and none has explicitly freed the
memory consumed by these objects.
In most cases, you do not need to take any action to reclaim memory. The runtime provides a garbage collector (GC),[27] a mechanism that automatically discovers when objects are no longer in use, and recovers the memory they had been occupying so that it can be used for new objects. However, there are certain usage patterns that can cause performance issues or even defeat the GC entirely, so it’s useful to understand how it works. This is particularly important with long-running processes that could run for days. (Short-lived processes may be able to tolerate a few memory leaks.)