TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
C# Coding Standard

Rule:  9@110Checked automatically with code checker

Synopsis:Each subscribe must have a corresponding unsubscribe
Severity Level:2
Category:Delegates and events

Subscribing to an event gives the object that sends the event, a reference to the subscribed object. If the subscribed object does not unsubscribe once that is not needed, then it will still be called. If for example, the subscribed object is disposed, then the event still is called on that disposed object (which usually is not intended), and also it is not garbage collected. Therefore it is good to ensure that for each subscribe that is done, also an unsubscribe is done, once listening to that event is no longer needed. The Dispose() implementation could be used to ensuring that all unsubscribes are done.