We extensively use events in our .net programs. Most of the times, it doesn’t give you debugging worries. However in some cases, it can become an issue where your object containing event handler doesn’t get garbage collected due to event raising object holding a reference to the listener object. This happens when you listen to the events from a long lived object compared to the listening object.If you are coding in VB.NET then using the handles clause will guard you to an extent. Just remember to set the withevents variable to nothing after done. This will remove bindings between your event handlers and the object.However, if we are programming in C# or have to use AddHandler statements in VB.NET for attaching event handlers, remember to explicitly detach the handler from the event. As I said earlier, most of the times this does not become an issue at all. However, while creating highly event driven classes for your application, you don’t want objects sticking around more than they need to be. Also since the handler is still attached to the event, the handler will get invoked each time the event is fired. You can think the issues arising when this happens.Keep an eye on how you attach event handlers and make sure that you are detaching them in time.
Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList