Do I need to Dispose to deregister events?
Posted
by Sean
on Stack Overflow
See other posts from Stack Overflow
or by Sean
Published on 2010-04-13T14:23:53Z
Indexed on
2010/04/13
14:32 UTC
Read the original article
Hit count: 299
Say I have two classes, and neither of them are GUI components. Class A is a short lived object that registers for an event declared by a long lived object B. For example
public A(B b)
{
b.ChangeEvent += OnChangeEvent;
}
If A never deregisters from B's event, will A never be garbage collected? Does A need a Dispose method just to deregister from B's event?
There is also a related second question. If A and B should both live for the entire execution time of the application, does A need to deregister?
© Stack Overflow or respective owner