Let\'s say we have the following setup:
public class ClassA
{
public event EventHandler SomeEvent;
}
public class ClassB : IDisposable
{
public void S
Nothing you have above would unhook your event handler. Since both a
and b
go out of scope at the same time, you'd be safe. Since a
and b
can both be collected, then a
will not keep b
alive.
If you were to raise the ClassA.SomeEvent
event after your using statement, then ClassB.DoSomething
will be called even though b
has been disposed. You would have to explicitly remove the event handler in this case.
If you were to retain a reference to a
somewhere else, then b
would be keep alive by a
. Again, because the event handler has not been removed.