473,327 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

what is the correct place for "RemoveHandler" code



regarding the answers I got from the thread
"Does each "New" needs a corresponding "Dispose" "
(http://www.developersdex.com/vb/mess...3582570&page=2)
I have some questions:

Till now, when I used dynamicCreatedControls with 'AddHandler',
I wrote the 'RemoveHandler' code in my function that was called
from the automaticGenerated Dispose function.
(I have added example at the end of this message. )

my questions:
1. Is this is the correct place for "RemoveHandler" code,
or that Dispose() only manages unmanaged resources ?
If so, where is the place for "RemoveHandler" code ?
2. I thought that by setting Me.myControl to Nothing I enable
the GC to collect it. Am I preventing the GC by this line
because I have referenced myControl in the code ?

Thanks.

Atara.

-----------------------------------------------------
Example for my 'RemoveHandler' code:

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
mcDisposeAllDynamic() ' ****** my added code.
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

Private Sub mcDisposeAllDynamic() ' ****** my function.
Dim c As Control
Dim iMax As Integer = Controls.Count - 1
Dim i As Integer
For i = iMax To 0 Step -1
c = Controls(i)
If (TypeOf c Is CheckBox) Then
Dim chb As CheckBox = CType(c, CheckBox)
RemoveHandler chb.CheckedChanged, AddressOf _
myCtrl_CheckedChanged
Me.Controls.Remove(chb)
chb.Dispose() : chb = Nothing
End If
Next i
End Sub
-----------------------------------------------------


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #1
0 1610

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

41
by: Mountain Bikn' Guy | last post by:
What is the current preferred way to save user preferences in dotnet? Is the registry the right place to do this? Can anyone recommend a good article (or book) for this topic? Thanks.
11
by: Brett | last post by:
What is the C# equivalent for this VB.NET code: Private WithEvents IE_Inst As New SHDocVw.InternetExplorer I get as far as: private SHDocVw.InternetExplorer IE_Inst = new...
1
by: Sean Nolan | last post by:
We have implemented unhandled error trapping at the application level and log these errors to our database. One error, however, the does not get trapped is when the connection pool has exceeded the...
0
by: Atara | last post by:
regarding the answers I got from the thread "Does each "New" needs a corresponding "Dispose" " (http://www.developersdex.com/vb/message.asp?p=&r=3582570&page=2) I have some questions: Till now,...
10
by: Eric G. Harrison | last post by:
We have a project with many other projects referenced (all of which are referenced at the project level and are included in the solution). Frequenly, if we make a change in project A (such as adding...
3
by: hartley_aaron | last post by:
Hi, I was trying to store the address of the my current handler for a particular event so as to simplify using AddHandler and RemoveHandler throughout my code. However, I cannot seem to get any...
16
by: abc my vclass | last post by:
C# has VB's "with" command? I like VB's with command, why don't know C# has it or not?
12
by: Tom | last post by:
I use dynamically created controls all the time. I.E. I create the control in code then use AddHandler to add the necessary delegates for processing (like Click, etc). Does one have to call...
4
by: FullBandwidth | last post by:
I have been perusing various blogs and MSDN pages discussing the use of event properties and the EventHandlerList class. I don't believe there's anything special about the EventHandlerList class in...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.