M
milop
Hello. I have a Winform (3.51) application and am using my own
ApplicationContext.
When I dispose forms it appears as though the memory is not being
deacllocated.
I created a test app that exhibits this behvior( below).
In the app there are two forms (Form1 and Form2), with one button on each
for that calls RaiseContinueButtonPressed (so form1 is shown, then form2,
then form1, etc.). As I click each button the memory usage rises and never
falls, even though I am calling each form's Dispose() method.
Anyone have any idea why the memory is not being deallocated?
Thanks in advance,
Mike
'-------- Example Code ------------
'-------- Program.vb -------
Public NotInheritable Class Program
<STAThread()> _
Public Shared Sub Main()
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Application.Run(New MyApplicationContext)
End Sub
End Class
'------- MyApplicationContext class -------------
Public Class MyApplicationContext
Inherits ApplicationContext
Private _oldForm As Windows.Forms.Form
Private _currentForm As Windows.Forms.Form
Public Sub New()
AddHandler MyEvents.ContinueButtonClicked, AddressOf
HandleContinueButtonClicked
_currentForm = New Form1()
_currentForm.Show()
End Sub
Private Sub HandleContinueButtonClicked(ByRef sender As
Windows.Forms.Form)
_oldForm = _CurrentForm
_CurrentForm = New Form2()
_oldForm.Close()
_CurrentForm.Show()
End Sub
End Class
Public Class MyEvents
' User clicked the button on the form::
Public Shared Event ContinueButtonClicked(ByRef sender As
Windows.Forms.Form)
Public Shared Sub RaiseContinueButtonClicked(ByRef sender As
Windows.Forms.Form)
RaiseEvent ContinueButtonClicked(sender)
End Sub
End Class
ApplicationContext.
When I dispose forms it appears as though the memory is not being
deacllocated.
I created a test app that exhibits this behvior( below).
In the app there are two forms (Form1 and Form2), with one button on each
for that calls RaiseContinueButtonPressed (so form1 is shown, then form2,
then form1, etc.). As I click each button the memory usage rises and never
falls, even though I am calling each form's Dispose() method.
Anyone have any idea why the memory is not being deallocated?
Thanks in advance,
Mike
'-------- Example Code ------------
'-------- Program.vb -------
Public NotInheritable Class Program
<STAThread()> _
Public Shared Sub Main()
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Application.Run(New MyApplicationContext)
End Sub
End Class
'------- MyApplicationContext class -------------
Public Class MyApplicationContext
Inherits ApplicationContext
Private _oldForm As Windows.Forms.Form
Private _currentForm As Windows.Forms.Form
Public Sub New()
AddHandler MyEvents.ContinueButtonClicked, AddressOf
HandleContinueButtonClicked
_currentForm = New Form1()
_currentForm.Show()
End Sub
Private Sub HandleContinueButtonClicked(ByRef sender As
Windows.Forms.Form)
_oldForm = _CurrentForm
_CurrentForm = New Form2()
_oldForm.Close()
_CurrentForm.Show()
End Sub
End Class
Public Class MyEvents
' User clicked the button on the form::
Public Shared Event ContinueButtonClicked(ByRef sender As
Windows.Forms.Form)
Public Shared Sub RaiseContinueButtonClicked(ByRef sender As
Windows.Forms.Form)
RaiseEvent ContinueButtonClicked(sender)
End Sub
End Class