Friday, March 19, 2010

.NET Memory Leaks

Since .NET applications run in the CLR as managed code, inexperienced developers may make the assumption they no longer need to be concerned with memory usage--after all, it's managed code and the garbage collector will take care of it, right?  Unfortunately, that isn't true.  Here's a StackOverflow post and here's another post discussing the issue.  Here is a detailed MSDN article.  The article notes these are the most common causes of memory leaks in the .NET world:

  • Static references
  • Event with missing unsubscription
  • Static event with missing unsubscription
  • Dispose method not invoked
  • Incomplete Dispose method
Last, here's a post talking about how to use C#'s 'using' statement as a way of making sure the Dispose method gets called on any Disposable object.

No comments: