One aspect of modern web development that sometimes seems to be taken for granted is memory management. While you might not need to create a custom boot disk anymore in order to run your application on a modern machine, it is still important to understand how your memory allocations are cleaned up. Two of the main components to cleaning up memory allocation are the garbage collector and the finalizer.
[Read more…]
Garbage Collection and the Finalizer
Common Pitfalls with IDisposable and the Using Statement
Memory management with .NET is generally simpler than it is in languages like C++ where the developer has to explicitly handle memory usage. Microsoft added a garbage collector to the .NET framework to clean up objects and memory usage from managed code when it was no longer needed. However, since the garbage collector does not deal with resource allocation due to unmanaged code, such as COM object interaction or calls to external unmanaged assemblies, the IDisposable pattern was introduced to provide developers a way to ensure that those unmanaged resources were properly handled. Any class that deals with unmanaged code is supposed to implement the IDisposable interface and provide a Dispose() method that explicitly cleans up the memory usage from any unmanaged code. Probably the most common way that developers dispose of these objects is through the using statement.
[Read more…]