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!