473,461 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 5275
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: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.