Yep, this line does the trick for me. I run it on a 5 minute timer...
try
{
System.Diagnostics.Process.GetCurrentProcess().Max WorkingSet =
System.Diagnostics.Process.GetCurrentProcess().Min WorkingSet;
}
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...
--
John Wood
EMail: first name, dot, second name at priorganize.com
"Bill Jones" <bi*******@worldnet.com> wrote in message
news:1u********************************@4ax.com...
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.