Memory Leak

partham

Active member
Joined
Dec 27, 2005
Messages
41
Location
Kolkata, India
Programming Experience
10+
Dear Sir,

I am programming a IVR Socket Server using VB.Net. In the application, I have coded as carefully as possible trying to ensure that all the objects that are created are destroyed when they go out of scope. However, when I run the application in the simulation environment, it shows alarming increase in the memory used by the executable. The application start by occupying about 26 MB. After processing 10000 requests, it shows the memory utilisation as about 94 MB.

I used a memory profiling tool. From the tool, I gather that the Generation 0 GCs are raising constantly as the application is running. After processing 10000 requests, the Generation 0 GCs are about 11000.

I would be very grateful if you could provide me some guidelines to be able to run the application without memory leaks.

The same application when I code using VB 6.0, takes about 12 MB at startup. Though this program also has memory leaks, it increased to about 15 MB after processing 10000 requests.

Why does the VB.Net application take so much of memory space at startup? Are there any mechanisms to be able to optimise this?

Very grateful in advance for you time and assistance.

Wishing you a very happy new year 2006.

Regards,
Partha.:(
 
.Net applications allocate all possible memory that may be used upon startup and in runtime, but is not actually using it. Windows will reassign some of that memory to other application if they need it. It's done for performance, so that the next thing user does in application is already allocated for.
It it really only a "cosmetic" problem, compare it to an applications working directory free disk space...
Have a look at this in depth discussion about the matter:
http://www.itwriting.com/dotnetmem.php

Here is a memory flush class you can have a try with, for example after application load do MemoryManagement.FlushMemory() and you will see real memory usage.
Do not over-use this, it will only downgrade your application and overall system performance.
VB.NET:
'.NET Application Memory Flush via Interop 
'http://addressof.com/blog/archive/2003/11/19/281.aspx
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
 
Just saw the tip in the link I gave, try minimizing the application and see the memory "usage" drop in Task Manager, maximize it again and Framework does it's job again reallocating resources..
 
Back
Top