Disposing EventHandlers

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
 
M

Mattias Sjögren

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
 

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

Top