I got a little confused in C # classes and their deconstructor.
I need to use several event handlers in an instance of the class that I get in the constructor:
public Foo(IFooHandler handler) { handler.Load += Load; handler.Close += Close; }
I need to unsubscribe from this event when the Foo class is destroyed. Do I perform IDisposable and unsubscribe there or in the deconstructor? I need to destroy these events, I can not do it differently.
For one of the classes, I create an instance, check the progress, and then the class instance goes out of scope. For another, it remains in MainForm until the form is closed. Firstly, this is what I'm worried about, because it still has a link to this event handler, and not to the correct operation.
I do not want a memory leak. When and how should I unsubscribe?
c # events winforms delegates
Sarah Fordington Aug 17 '09 at 12:51 2009-08-17 12:51
source share