logo       

Adding and removing event handlers: msg#00128

windows.devel.dotnet.web

Subject: Adding and removing event handlers

We have a web app where we are experiencing OutOfMemoryException errors
fairly regularly particularly with concurrent use of the same pages.

The pages that cause the problem most frequently have several handlers
delegated to handle events using AddHandler() (VB not C#).

Unfortunately we have forgotten to tidy up the handlers using RemoveHandler
(). My understanding is that this can cause memory leaks because the
objects handling the events (in this case, the pages) always remain in
memory because there is always a reference to them.

My suspicion is that this is the cause of our problem but my question goes
further than this.

Should event handlers be removed in a particular order with respect to the
order they are added? eg. should they be removed in the same order,
reverse order or doesnâ??t it matter?

Most of the handlers are added in the Load handlers of pages and user
controls. I assume that a good place to remove them would be in the Unload
handler for these controls. Am I correct?

Is there a recommended pattern for adding and removing event handlers?

Thanks for any advice you can give.

Alan Williams
RTIX Ltd.

===================================
This list is hosted by DevelopMentor® http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise