Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 6th, 2004, 05:53 PM
Registered User
 
Join Date: Nov 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Beware the AddHandler

I would appreciate any comments on this issue, as I cannot find any resources elsewhere.

Scenario:
In a Form, add a Control A and a Control B, where A subscribes to an event fired by B. I'm using VB.NET, so that would be an AddHandler. Now make the Form delete Control A .

Problem:
Did you think you got rid of Control A? Think again, cause Control A is tied up to Control B through Control B's EventHandlerList. This is quite annoying since Control B doesn't know that Control A is deleted, and there is no way the Form can know there is more references to A. The consequence, if you have a lot of Control A's, is a major memoryleak.

Solution:
Help me out here. The only way I have found to avoid this mess is to force Control A to release it's eventhandlers with RemoveHandler. And the Form must call this method. Setting Control A to Nothing or just make the variable go out of scope doesn't help...

oes





Similar Threads
Thread Thread Starter Forum Replies Last Post
Why is addhandler for linkbutton.click not working rsearing ASP.NET 2.0 Basics 7 November 12th, 2007 06:06 PM
addhandler catch 22 roog ASP.NET 1.0 and 1.1 Professional 2 February 20th, 2006 01:01 PM
AddHandler from String [email protected] Pro VB.NET 2002/2003 2 July 6th, 2003 04:18 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.