Reduce Memory Footprint at Startup

  • Thread starter Thread starter Bill Jones
  • Start date Start date
B

Bill Jones

I have a very simple little utility program that when started shows
about 10meg in Task Manager. I'd like to distribute this program, but
I'm certain some semi-savvy users will balk over it's size not
understanding about Automatic Garbage Collection and will just say C#
is a pig.

If I Minimize the app and then Restore it, memory drops to about 2meg.
Can I somehow programmatically cause this memory reduction without
resorted to something crude like setting the state to minimized then
back normal. I tried calling GC.Collect() and it doesn't show any
change in Task Manager.
 
Yep, this line does the trick for me. I run it on a 5 minute timer...

try
{
System.Diagnostics.Process.GetCurrentProcess().MaxWorkingSet =
System.Diagnostics.Process.GetCurrentProcess().MinWorkingSet;
}
catch
{
}

Keep in mind it has to be in a try/catch, because for some reason it thinks
that setting the max working set to the minimum working set size is
'invalid'... however, it trims the working set anyway.

Also keep in mind that this pages the application out to disk, and therefore
could reduce the responsiveness of various functions within the application
after the call is made. It also means that the working set will gradually
increase again over time...

At least you can do it without resorting to unmanaged code...
 
It's not *that* bad, in that 99% of memory consumption complaints come from
users -- and for users perception is everything. As long as they're willing
to accept the trade-off in responsiveness...
 
Back
Top