To me the dispose method is supposed to destroy the live
objects and free up some memory occupied by the object
after CG called.
To see this, I created a simple Form with two buttons. One
to instantiate a class and run a dummy loop and the other
to dispose that object.
I copied the code at below so you may give me an idea. In
the following code the only reason that Class1
inherited "System.Windows.Forms.Form" is to use Form's
dispose method later to destroy this class (Is this the
right way?)
Test:
First I clicked on the button1 to run the dummy loop and
allocate some memory (and I saw the memory usage went up)
and then I clicked on button2 to dispose this object but
didn't see any dropping in memory usage even I saw some
increase after a few minutes.
Question:
Why the dispose doesn't work? Do I miss something? Do I
need to have my own dispose? How?
Please advice.
Thanks.
Public Class Class1
Inherits System.Windows.Forms.Form
Function dummyloop() As Integer
Dim i As Double
For i = 1 To 100000
Dim j As String = "memory"
Dim h As String = "testing"
Next
Return i
End Function
End Class
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
cls = New Class1()
TextBox1.Text = cls.dummyloop()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button2.Click
cls.Dispose()
End Sub
[quoted text, click to view] >-----Original Message-----
>Hi,
>We are experiencing a huge page faults and virtual memory
>in task manager after working a few hours with an
>application developed by VB.NET uses web services . This
>causes an extremely slow down in the application respond.
>Any way I could control this problem?
>
>I called the following method in a few places to control
>the memory. Is this may cause the problem the page faults
>and virtual memory to go up?
>
>Private Declare Function SetProcessWorkingSetSize
>Lib "kernel32.dll" (ByVal hProcess As IntPtr, ByVal
>dwMinimumWorkingSetSize As Int32, ByVal
>dwMaximumWorkingSetSize As Int32) As Int32
> Public Function NewSaveMemory() As Int32
> GC.Collect()
> GC.WaitForPendingFinalizers()
> SetProcessWorkingSetSize
>(Process.GetCurrentProcess.Handle, -1, -1)
> End Function
>
>.