What is the correct way of destroying an object who is listening to delegate events?

  • Thread starter Thread starter Darren
  • Start date Start date
D

Darren

If I have objA that has registered for delegate events from objB and
objA is set to null (or is destroyed by going out of scope), should
objA do anything to unregister from these events before it is
destroyed? For instance in the destructor should it be doing something
like this:

objA_destructor()
{
objB.A_delegate -= OnDelegateEvent(MyFunction)
}

Or can this be done automatically somehow???

Thanks in advance,
Darren.
 
Darren,

This should be handled by the garbage collector in the .Net CLR, so you
don't need to do anything.

Dan.
 
Back
Top