Memory usage

T

Teemu

I have very simple app that has some buttons and labels. When I start my
app, Task manager shows that application is using about 20 mb memory, quite
a lot in my opinion.

Then, I minimize my app. When the app is minimized, it requires only 700 kb
memory. But then the most intresting part: When I normalize my app again
from the taskbar, the app requires only 2 mb memory and in the app nothing
is happened meanwhile.

Why application requires in the first time 20 mb memory and after
minimize-maximize operation the amount is much smaller?

Teemu
 
H

Herfried K. Wagner [MVP]

Teemu said:
I have very simple app that has some buttons and labels. When I start my
app, Task manager shows that application is using about 20 mb memory, quite
a lot in my opinion.

Don't worry about that too much. Memory usage shown for .NET-based
applications is not accurate in task manager because it doesn't show how
much of the memory assigned to the process is really used.
Then, I minimize my app. When the app is minimized, it requires only 700
kb memory. But then the most intresting part: When I normalize my app
again from the taskbar, the app requires only 2 mb memory and in the app
nothing is happened meanwhile.

Why application requires in the first time 20 mb memory and after
minimize-maximize operation the amount is much smaller?

I suggest to take a look at this article:

The working set of an application is trimmed when its top-level window is
minimized
<URL:http://support.microsoft.com/?scid=kb;EN-US;293215>
 
T

Teemu

Herfried K. Wagner said:
Don't worry about that too much. Memory usage shown for .NET-based
applications is not accurate in task manager because it doesn't show how
much of the memory assigned to the process is really used.


I suggest to take a look at this article:

The working set of an application is trimmed when its top-level window is
minimized
<URL:http://support.microsoft.com/?scid=kb;EN-US;293215>

Thanks for your quick answer!

-Teemu
 
M

m.posseth

i wish it was more known to the outside world how .Net handles memory

for one of our customers i had to built this code in one of our distributed
apps :)

Public Sub New()

MyBase.New()

M_dtLastUsage = Date.Now

If IsNothing(oTimer) Then

oTimer = New System.Threading.Timer(oCallback, Nothing,
System.TimeSpan.FromMinutes(0), System.TimeSpan.FromMinutes(1))

End If

End Sub









Private M_dtLastUsage As DateTime

Private oCallback As New TimerCallback(AddressOf OnTick)

Private oTimer As Threading.Timer

Private Declare Auto Function SetProcessWorkingSetSize Lib "kernel32.dll"
(ByVal procHandle As IntPtr, ByVal min As Int32, ByVal max As Int32) As
Boolean



Public Sub OnTick(ByVal stateInfo As Object)

Dim DtCurrent As DateTime = Date.Now

Dim elapsed_time As TimeSpan

elapsed_time = DtCurrent.Subtract(M_dtLastUsage)

If elapsed_time.TotalMinutes >= 1 Then

oTimer.Dispose() : oTimer = Nothing

Try

Dim Mem As Process = Process.GetCurrentProcess()

SetProcessWorkingSetSize(Mem.Handle, -1, -1)

Catch ex As Exception

End Try

End If

End Sub



every time the user performs an action this method is called in a singleton
class

Friend Function fblnGuidExists(ByVal strGuid As String, ByRef stUservals As
SessionVals) As Boolean

M_dtLastUsage = Date.Now

If IsNothing(oTimer) Then

oTimer = New System.Threading.Timer(oCallback, Nothing,
System.TimeSpan.FromMinutes(0), System.TimeSpan.FromMinutes(1))

End If

If htSessions.ContainsKey(strGuid) Then

Dim structSessionVals As SessionVals = CType(htSessions.Item(strGuid),
SessionVals)

With structSessionVals

..dtLastSessionAccess = Date.Now

End With

htSessions.Remove(strGuid)

htSessions.Add(strGuid, structSessionVals)

stUservals = structSessionVals

Return True

End If

End Function


I guess i do not have to tell you what happens here ;-)

by the way the customer is verry happy now

regards

Michel Posseth [MCP]
 

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

Similar Threads


Top