M
Marina
Hi,
Consider the following situation
I have the following routine running repeatedly (curControl is a UserControl
with say 1000 textboxes and a big array of strings):
Public Sub AddControl(ByVal ctlName As String)
If Not IsNothing(curControl) Then
Me.Controls.Remove(curControl)
End If
Dim assemb As [Assembly] = [Assembly].Load("MyControlAssembly")
curControl = CType(assemb.CreateInstance(ctlName), UserControl)
curControl.Location = New Point(150, 20)
Me.Controls.Add(curControl)
End Sub
Now, running this Sub over and over, the memory stays more or less the same.
That is to say, it goes up a litte bit - maybe 4-20K, but nothing huge.
Now, consider this version:
Public Sub AddControl(ByVal ctlName As String)
If Not IsNothing(curControl) Then
curControl.Dispose()
End If
Dim assemb As [Assembly] = [Assembly].Load("MyControlAssembly")
curControl = CType(assemb.CreateInstance(ctlName), UserControl)
curControl.Location = New Point(150, 20)
End Sub
Now, in this version, the control is not being added to the form - it is
just created.
In this case, the memory goes up by about .5 MB every time this code runs.
Now, the questions is, why is it that in the first scenario, the control is
cleaned up properly - but in the second scenario (where Dispose is actually
being closed), it is not. The memory keeps climbing up and up.
Thanks
Consider the following situation
I have the following routine running repeatedly (curControl is a UserControl
with say 1000 textboxes and a big array of strings):
Public Sub AddControl(ByVal ctlName As String)
If Not IsNothing(curControl) Then
Me.Controls.Remove(curControl)
End If
Dim assemb As [Assembly] = [Assembly].Load("MyControlAssembly")
curControl = CType(assemb.CreateInstance(ctlName), UserControl)
curControl.Location = New Point(150, 20)
Me.Controls.Add(curControl)
End Sub
Now, running this Sub over and over, the memory stays more or less the same.
That is to say, it goes up a litte bit - maybe 4-20K, but nothing huge.
Now, consider this version:
Public Sub AddControl(ByVal ctlName As String)
If Not IsNothing(curControl) Then
curControl.Dispose()
End If
Dim assemb As [Assembly] = [Assembly].Load("MyControlAssembly")
curControl = CType(assemb.CreateInstance(ctlName), UserControl)
curControl.Location = New Point(150, 20)
End Sub
Now, in this version, the control is not being added to the form - it is
just created.
In this case, the memory goes up by about .5 MB every time this code runs.
Now, the questions is, why is it that in the first scenario, the control is
cleaned up properly - but in the second scenario (where Dispose is actually
being closed), it is not. The memory keeps climbing up and up.
Thanks