473,320 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Reduce Memory Footprint at Startup

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.
Nov 16 '05 #1
4 5270
Well, I guess you know that it's bad to do this...

But, you can try calling SetProcessWorkingSetSize and that might change what
appears in task manager. Here's the P/invoke sig:
http://www.pinvoke.net/default.aspx/...WorkingSetSize

-mike
MVP

"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.

Nov 16 '05 #2
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.

Nov 16 '05 #3
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...

--
John Wood
EMail: first name, dot, second name at priorganize.com
"Michael Giagnocavo [MVP]" <mg*******@atrevido.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Well, I guess you know that it's bad to do this...

But, you can try calling SetProcessWorkingSetSize and that might change what appears in task manager. Here's the P/invoke sig:
http://www.pinvoke.net/default.aspx/...WorkingSetSize

-mike
MVP

"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.


Nov 16 '05 #4
Beautiful!

On Sun, 11 Jul 2004 15:01:48 -0400, "John Wood" <sp**@isannoying.com>
wrote:
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().Mi nWorkingSet;
}
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...


Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

226
by: Stephen C. Waterbury | last post by:
This seems like it ought to work, according to the description of reduce(), but it doesn't. Is this a bug, or am I missing something? Python 2.3.2 (#1, Oct 20 2003, 01:04:35) on linux2 Type...
2
by: Mike Peretz | last post by:
I am trying to optimize my C# program, but no matter what I try the application keeps eating memory. I verified all the references and even got special software to count references. I made sure all...
1
by: francois | last post by:
I'm looking for C++ classes library to be used instead of STL. As I'm working on a tiny embedded system 16MB up to 32MB, I need to reduce memory footprint needed by the STL due to its genericity....
1
by: Derrick | last post by:
Thanks to many on this newsgroup, I now have a prototype Windows Forms C# app that reads xml documents into DataSets via XmlDataDocument, and does *stuff* with it. I basically have about 25 megs...
1
by: Derrick | last post by:
I am reading in xml files that equate to sql tables, via XmlDataDocument, and then operating on the DataSet. With the most simple app that just loads the xml doc, I see the memory footprint of the...
6
by: Ziphyre | last post by:
Hi, I have a simple windows application, it doen't have any form, or expensive resource, just a simple exe. Its size compiled in release mode is approximately 23KB. But when I run it, its size...
8
by: Bob Dufour | last post by:
We got a windows form application that we wrote in VB.Net. Essentially its a manager for a list of persons and their contacts and some other info about the persons. No rocket science but lots of...
12
by: Varun Kacholia | last post by:
Apologies if this has been answered somewhere, but Google did not produce any concrete results. I would like to find out the memory footprint of a vector<T>. I tried to dig in the STL code and...
9
by: neil.johnston | last post by:
I have a cut down example program that uses multiset to order some data. The data arrives from various sources and has a time stamp, data with identical timestamps can arrive and due to fifo's and...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.