Disposing EventHandlers

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

In a windows app is it necessary to explicity release delegates from events
by implementing dispose, or should the framework take care of this?

I've read that you only need to implement IDisposable when handling
unmanaged resources, which makes sence... however...

Investigating a memory leak in a large application there are over 80,000
referrences to a single button in the GC after 30 mins runtime. It seems that
not implementing dispose and releasing the references causes this. Can
someone confirm?

Thanks,

Mike
 
Mike,
In a windows app is it necessary to explicity release delegates from events
by implementing dispose, or should the framework take care of this?

If you want the object handling the event to be eligible for garbage
collection before the event provider is, you have to remove the
handler from the event. Whether that removal code should go in a
Dispose method or somewhere else depends on your class design.


Mattias
 
Back
Top