Reducing Mem Usage

J

John Wood

As everybody points out, the best way to reduce the memory footprint of a
..net application is to minimize it and restore it. This can make my app go
from 40Mb of usage to about 3Mb of usage. Of course it will grow again
gradually...

My clients have requested that I somehow automate this... so that it
achieves the same result periodically without them having to minimize the
application. They claim otherwise it's difficult for them to monitor their
users' machines for resource utilization.

Any ideas?

TIA,
John
 
N

Nicholas Paldino [.NET/C# MVP]

John,

You can call the SetProcessWorkingSetSizeEx API function, passing in -1
for the dwMinimumWorkingSetSize and dwMaximumWorkingSetSize parameters to do
this.

Hope this helps.
 
J

John Wood

Ooh coolio, thanks!
Very useful information.

Nicholas Paldino said:
John,

You can call the SetProcessWorkingSetSizeEx API function, passing in -1
for the dwMinimumWorkingSetSize and dwMaximumWorkingSetSize parameters to do
this.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

John Wood said:
As everybody points out, the best way to reduce the memory footprint of a
.net application is to minimize it and restore it. This can make my app go
from 40Mb of usage to about 3Mb of usage. Of course it will grow again
gradually...

My clients have requested that I somehow automate this... so that it
achieves the same result periodically without them having to minimize the
application. They claim otherwise it's difficult for them to monitor their
users' machines for resource utilization.

Any ideas?

TIA,
John
 
J

John Wood

Actually I have a question about this...
Why *does* the workingset gradually increase in my .net app, is this an
indication of a leak or is it normal for the amount to increase over time?

My understanding (from reading the docs on it) is that this function pages
out the application, does this mean that there will be a performance hit the
next time they try to use the application after I run this function?

Thanks again,
John

Nicholas Paldino said:
John,

You can call the SetProcessWorkingSetSizeEx API function, passing in -1
for the dwMinimumWorkingSetSize and dwMaximumWorkingSetSize parameters to do
this.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

John Wood said:
As everybody points out, the best way to reduce the memory footprint of a
.net application is to minimize it and restore it. This can make my app go
from 40Mb of usage to about 3Mb of usage. Of course it will grow again
gradually...

My clients have requested that I somehow automate this... so that it
achieves the same result periodically without them having to minimize the
application. They claim otherwise it's difficult for them to monitor their
users' machines for resource utilization.

Any ideas?

TIA,
John
 
S

Stu Smith

Nicholas Paldino said:
John,

You can call the SetProcessWorkingSetSizeEx API function, passing in -1
for the dwMinimumWorkingSetSize and dwMaximumWorkingSetSize parameters to do
this.

Ermm... wouldn't that be a massive performance hit? From MSDN:

"If both dwMinimumWorkingSetSize and dwMaximumWorkingSetSize have the
value -1, the function temporarily trims the working set of the specified
process to zero. This essentially swaps the process out of physical RAM
memory."

So you're swapping the process out, and then presumably swapping it back in
as needed. Pretty slow I'd have thought.

What exactly is the problem with memory? Is it simply that it's a "big"
number in task manager, or is there an actual performance issue?

Stu

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

John Wood said:
As everybody points out, the best way to reduce the memory footprint of a
.net application is to minimize it and restore it. This can make my app go
from 40Mb of usage to about 3Mb of usage. Of course it will grow again
gradually...

My clients have requested that I somehow automate this... so that it
achieves the same result periodically without them having to minimize the
application. They claim otherwise it's difficult for them to monitor their
users' machines for resource utilization.

Any ideas?

TIA,
John
 
J

John Wood

Yeah I can't imagine it's much different from just minimizing the app and
restoring it... which doesn't add much hit at all.

AlexS said:
I use this approach on rather feeble laptop with 256MB - no performance hit
is perceptible. My app memory jumps between 30MB and 0.5MB without any
perceptible disk activity. However this would depend on application itself:
if you modify a lot of data in RAM, then reducing working set could cause
actual swapping. If you have mostly code and not changed data - swapping
will just free memory.

HTH
Alex

Stu Smith said:
message news:[email protected]...
John,

You can call the SetProcessWorkingSetSizeEx API function, passing in -1
for the dwMinimumWorkingSetSize and dwMaximumWorkingSetSize parameters
to

Ermm... wouldn't that be a massive performance hit? From MSDN:

"If both dwMinimumWorkingSetSize and dwMaximumWorkingSetSize have the
value -1, the function temporarily trims the working set of the specified
process to zero. This essentially swaps the process out of physical RAM
memory."

So you're swapping the process out, and then presumably swapping it back in
as needed. Pretty slow I'd have thought.

What exactly is the problem with memory? Is it simply that it's a "big"
number in task manager, or is there an actual performance issue?

Stu

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

As everybody points out, the best way to reduce the memory footprint
of
a
.net application is to minimize it and restore it. This can make my app
go
from 40Mb of usage to about 3Mb of usage. Of course it will grow again
gradually...

My clients have requested that I somehow automate this... so that it
achieves the same result periodically without them having to
minimize
the
application. They claim otherwise it's difficult for them to monitor their
users' machines for resource utilization.

Any ideas?

TIA,
John
 
A

AlexS

I use this approach on rather feeble laptop with 256MB - no performance hit
is perceptible. My app memory jumps between 30MB and 0.5MB without any
perceptible disk activity. However this would depend on application itself:
if you modify a lot of data in RAM, then reducing working set could cause
actual swapping. If you have mostly code and not changed data - swapping
will just free memory.

HTH
Alex

Stu Smith said:
message news:[email protected]...
John,

You can call the SetProcessWorkingSetSizeEx API function, passing in -1
for the dwMinimumWorkingSetSize and dwMaximumWorkingSetSize parameters
to

Ermm... wouldn't that be a massive performance hit? From MSDN:

"If both dwMinimumWorkingSetSize and dwMaximumWorkingSetSize have the
value -1, the function temporarily trims the working set of the specified
process to zero. This essentially swaps the process out of physical RAM
memory."

So you're swapping the process out, and then presumably swapping it back in
as needed. Pretty slow I'd have thought.

What exactly is the problem with memory? Is it simply that it's a "big"
number in task manager, or is there an actual performance issue?

Stu

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

John Wood said:
As everybody points out, the best way to reduce the memory footprint
of
 

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