Do I need to Dispose to deregister events?
- by Sean
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?