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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top