If I have an application with only a few event handlers registered (and the objects using the events are not disposed until the application is closed), do I really need to worry about unregistering those handlers? The only good reason I could see is that there might be a little extra overhead if events are being fired that you dont necessarly care about (i.e you have multiple handlers registered to one event). Is there any other good reason to? Anyone run into major issues because they didnt unregister events?
Share
If you have
Apublishing an event, andBsubscribing to an event (the handler), then it is only a problem not to unsubscribe ifAis going to live a lot longer thanB. Basically, the event subscription means thatAcan still seeB, so would prevent it from being garbage collected, and would still fire events on it even if you’ve forgotten about it (and perhapsDisposed()it).For example, this is a problem if
Ais a static event, and your app runs for a while afterBdies… ButBwill live as long asA, thusBwill not be garbage collected.It is important to note, one might ask the following:
And the answer to that is “no”. B has no reference to A through the event; A will be collected as normal