Please can anyone recommend a quick checklist / best practice guide to help us avoid simple (but subtle) mistakes that cause could cause memory leaks in .net apps
I find
I can start to suggest that one should always be aware of IDisposable
objects and how to properly dispose them. Also, be very careful with the state in you app. Grab only objects when it's absoluttly necessary. If object A is goind to live for a long period of time in your app, always try not making dependencies between A and other objects.
Check for static variables which don't need to be there in the memory after usage, check for event handling references, any finalizaers which are blocking other finalizers from being collected and also if there are any un managed references to any DLLs or COM+ objects
The short answer is non-obvious references.
To add some details:
Number one would be event handlers that are attached and never detached.
If the subscriber to the event lives longer than the producer of the event and the subscriber doesn't disconnect the event handler then object firing the events will remain alive as there's still a reference to it through the subscribing object.
Circular references in value-classes (commonly in the model-layer of your application) can easily hide their leaks as well. In theory, don't do them, in practice, be aware whenever you need to do them :)
The number one cause of memory leaks in managed applications, in my opinion, is mistakenly believing that you have a memory leak, when in fact you haven't measured properly. Be sure to use a memory profiler to measure exactly what kind of memory leak you have. You may find that you have some other problem.
But when the leak is real, the major cause would be references to objects keeping those objects live when they're not really needed. Implementing a using statement for almost all objects implementing IDisposable is a good start. The only exception I know of is WCF proxy classes, which should be accessed with a try/catch/finally, and not a using statement.