Jessica Fosler recently posted a great summary on common causes for .NET memory leaks ("You gotta learn to let it go: Top 4 memory leaks"). If you're leaking memory, I'd strongly suggest this as as starting point.
In my experience, static/shared events are the most likely culprit. Anytime you're dealing with a static event, check and double-check to make sure you're unregistering your handlers during cleanup. Here's what Jessica says about it:
Make sure you know who you're giving your object out to. If you're stuffing your object in a static (or shared) list, it should be removed at some point in time, as that shared list will hold open the lifetime of your object. This also goes for hooking onto static events. (I've mentioned this one before.) The most common culprits are SystemEvents.UserPreferenceChanged and Application.Exit, Application.Idle etc. If you're hooking onto these events, remember to unhook when you're ready for cleanup, otherwise the Application and/or SystemEvents class will keep your object alive.
Make sure you know who you're giving your object out to. If you're stuffing your object in a static (or shared) list, it should be removed at some point in time, as that shared list will hold open the lifetime of your object.
This also goes for hooking onto static events. (I've mentioned this one before.) The most common culprits are SystemEvents.UserPreferenceChanged and Application.Exit, Application.Idle etc. If you're hooking onto these events, remember to unhook when you're ready for cleanup, otherwise the Application and/or SystemEvents class will keep your object alive.
Remember Me
a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u
Page rendered at Friday, November 21, 2008 6:48:46 AM (Central Standard Time, UTC-06:00)
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.