.net memory leak problem in exe

A

anandav2001

Hello developers,

I have created an executable(system tray application) in VS.net 2003
using VB.net. My app was taking 30 MB memory(since some web services
call are there which happens for each 10 sec checking internet is
available or not). Inorder to reduce huge memory consumption, what i
used is

Public Class MemoryManagement
Private Declare Function SetProcessWorkingSetSize Lib
"kernel32.dll" ( _
ByVal process As IntPtr, _
ByVal minimumWorkingSetSize As Integer, _
ByVal maximumWorkingSetSize As Integer) As Integer

Public Shared Sub FlushMemory()
GC.Collect()
GC.WaitForPendingFinalizers()
If (Environment.OSVersion.Platform = PlatformID.Win32NT) Then

SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1)
End If
End Sub
End Class

Now i call FlushMemory on every 10 secs.

Now the memory consumption got reduced to 2 MB..But the problem is
after running this application for several days continously(say 1 week)
i got .net memory leak exception. I heard that .net memory exception
comes only if your application doesnot leave memory when other apps
need it. Can anyone guide me correctly...

Any help in this regard is greatly appreciated......

Regards,

Anand. A.V
 
Z

Zvonko Keber

SetProcessWorkingSetSize does not solve your memory consumption. It only
trims the part of memory that process' once occupied.
You don't need the SetProcessWorkingSetSize at all.

You are probably watching the "Memory Usage" column in task manager. You
should be watching "VM size" column, which is hidden by default. This is
your application's allocated private bytes (total amount of memory allocated
by the process).

You need to make sure you dispose every object you create. If the object
doesn't implement a Dispose method, you should make sure that all references
to the object are lost (every time you associate a variable with the object,
reference is added and you need to set those variables to Nothing).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top