In battles with .NET resource leaks (memory / descriptors / threads / etc.), we found one culprit, which is above all higher: delaying event handlers. If I have an object that I would like to delete, but I still have an event handler registered for the events of this object, then the object will not disappear - these zombies multiply and are built together in chains until boom! your managed application has a resource leak for all purposes and tasks.
We took the shotgun approach and broke our most used and heaviest classes for events, which we add both manually and using the VB.NET keyword βHandlesβ and ensure that RemoveHandler / - = Dispose is called for each of them. We are also clearly destroying as much as possible.
ANTS is a great tool to keep track of this, but it is not a simple tool (but it is the simplest tool I have found for these problems). Take some time to familiarize yourself with it, and if you are on version 5, use these new filters.
Unfortunately, there is no silver bullet, this is one of my biggest hype with .NET, because usually you do not know that you have a problem until it becomes terribly widespread and difficult to reign.
STW
source share