Memory ups and downs

L

Lloyd Sheen

I noticed a post asking why a simple form when loaded takes 20,000K. I
decided to try it myself and came up with the following results (number are
from Task Manager Win XP-Pro)

Form Load
16,720K 12:44 PM 5/1/2004
16,996K 1:26 PM 5/1/2004
17,016K 1:29 PM 5/1/2004
Minimize
3,976K 1:30 PM 5/1/2004
Restore
4,740K 1:38 PM 5/1/2004
System completely idle
6,444K 2:04 PM 5/1/2004
Move Form
6,560K 2:07 PM 5/1/2004
System Idle
6,600K 2:17 PM 5/1/2004
Minimize
672K 2:18 PM 5/1/2004
Restore
3,700K 2:18 PM 5/1/2004
System Idle
3,896K 2:35 PM 5/1/2004
Close other apps
5,116K 2:36 PM 5/1/2004
Open IE
5,692K 2:38 PM 5/1/2004
System Idle
5,856K 2:57 PM 5/1/2004
6,540K 3:11 PM 5/1/2004

Even with GC these numbers are hard to justify. Seem as if a minimize of
the app caused a huge GC so maybe all win app's should load then minimize to
reduce memory usage?

LLoyd Sheen
 
H

Herfried K. Wagner [MVP]

* "Lloyd Sheen said:
I noticed a post asking why a simple form when loaded takes 20,000K. I
decided to try it myself and came up with the following results (number are
from Task Manager Win XP-Pro)

Form Load
16,720K 12:44 PM 5/1/2004
16,996K 1:26 PM 5/1/2004
17,016K 1:29 PM 5/1/2004
Minimize
3,976K 1:30 PM 5/1/2004
Restore
4,740K 1:38 PM 5/1/2004
System completely idle
6,444K 2:04 PM 5/1/2004
Move Form
6,560K 2:07 PM 5/1/2004
System Idle
6,600K 2:17 PM 5/1/2004
Minimize
672K 2:18 PM 5/1/2004
Restore
3,700K 2:18 PM 5/1/2004
System Idle
3,896K 2:35 PM 5/1/2004
Close other apps
5,116K 2:36 PM 5/1/2004
Open IE
5,692K 2:38 PM 5/1/2004
System Idle
5,856K 2:57 PM 5/1/2004
6,540K 3:11 PM 5/1/2004

Even with GC these numbers are hard to justify. Seem as if a minimize of
the app caused a huge GC so maybe all win app's should load then minimize to
reduce memory usage?

The reason is that the working set is reduced if the form is minimized
because Windows assumes that a minimized application is idle most of the
time because the user cannot work with it. Notice that the results
taken from Task Manager are not exact and do not say much about how much
memory an application really takes.
 
J

Jason Newell

Internally, they must be using one of the native Win32 methods
SetProcessWorkingSetSize(), SetProcessWorkingSetSizeEx() or
EmptyWorkingSet(). Notice that in the .NET framework, Process.WorkingSet is
read-only, hmm (Do as I say, not as I do?).
I've used SetProcessWorkingSetSize() in a .NET Form Application and it
works the same as when you Minimize the form, although I would bet money
it's not recommended.

MSDN Article:
(PRB: An Application's Working Set Is Trimmed When Its Top-Level Window Is
Minimized)
http://support.microsoft.com/default.aspx?scid=kb;en-us;293215
 
H

Herfried K. Wagner [MVP]

* "Jason Newell said:
Internally, they must be using one of the native Win32 methods
SetProcessWorkingSetSize(), SetProcessWorkingSetSizeEx() or
EmptyWorkingSet(). Notice that in the .NET framework, Process.WorkingSet is
read-only, hmm (Do as I say, not as I do?).
I've used SetProcessWorkingSetSize() in a .NET Form Application and it
works the same as when you Minimize the form, although I would bet money
it's not recommended.

ACK. It works, but it's not recommended.
MSDN Article:
(PRB: An Application's Working Set Is Trimmed When Its Top-Level Window Is
Minimized)
http://support.microsoft.com/default.aspx?scid=kb;en-us;293215

;-)
 

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