Groups | Blog | Home
all groups > dotnet performance > april 2007 >

dotnet performance : memory usage minimized


user411
4/6/2007 10:01:30 AM
..Net 1.1

I have developed an app that uses alot of double buffered forms. When minimized the app only uses about 1 meg of memory (as shown in taskmgr). Does garbage collection get triggered when you minimize?

When restored, the app starts at around 8 megs, then creeps up towards 100 megs. Is this normal? Is the double buffering using garbage collected buffers or is it implemented at a lower level then then dotnet framework?

just wondering, thanks
---
schneider
5/7/2007 1:40:31 PM
Yes,
The task manager is not working properly.

[quoted text, click to view]

Chris Mullins [MVP]
5/7/2007 3:33:59 PM
When you minimize your application, Windows (not .Net, but Windows itself)
trims your working set. This means, as far as Task Manager is concerned,
that you suddenly need far less memory.

This is something you can do yourself, as you can read about at:
http://www.coversant.com/Coversant/Blogs/tabid/88/EntryID/4/Default.aspx

In all of the WinForms apps that we build these days, we use this approach
to "Trim the Working Set" at strategic times. If we don't do this, we end up
using 100, 200 or 300 megs of memory. By keeping the working set trimmed,
our process keeps it's head low, and just chugs along.

--
Chris Mullins, MCSD.NET, MCPD:Enterprise, Microsoft C# MVP
http://www.coversant.com/blogs/cmullins

[quoted text, click to view]

Chris Mullins [MVP]
5/7/2007 4:43:29 PM
[quoted text, click to view]

We know the areas that tend to dramatically expand the working set size, so
we trim it just after those events. For example (this is for an Instant
Messaging Client):
- After login (or logout) is complete
- After we create a new Chat Form (aka: Tab Page)
- When a Tab Page is Closed (aka: a Conversation is closed)
- When the user changes options or settings
- When the user hits "Clear All" in a Chat Window

There are a few other areas, but these are the big ones. In general, we
attempt to shink the working set after we do events that we expect to have a
signifigant impact on it.

With these calls in there, the application tends to hover (in the Task
Manager, which is the only thing that matters) around 10 to 20 megabytes of
memory. If we're really agressive about things (using a timer etc) we can
get it lower, but there is then a noticable impact on application
performance.

If we remove these calls completly, after the app has been running for 4 or
5 hours (it's an IM client, remember, so it runs all day long on the
desktop) the memory usage hovers in the 200 to 300 megabyte range, and will
sometimes go higher.

... and before you ask, we're not leaking memory. The application has been
profiled a number of times with both performance and memory profilers and
things look pretty good.

The interaction between .Net WinForms applications and the Win32 Memory
Manager seems (to me) one of the weakest areas of the overall platform. Any
signifigant (any many insignifigant) application ends up taking hundreds and
hundreds of megabytes of memory, even though they're not doing anything with
it. This is frustrating for developers and users alike, and just plain
shouldn't be happening on a platform as mature as this.

--
Chris Mullins, MCSD.NET, MCPD:Enterprise, Microsoft C# MVP
http://www.coversant.com/blogs/cmullins

Alvin Bruney [MVP]
5/7/2007 7:14:59 PM
how do u trim ur working set at strategic times?

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley


[quoted text, click to view]

Jon Skeet [C# MVP]
5/7/2007 7:46:26 PM
[quoted text, click to view]

No, it's working properly - just not displaying what people think it
displays.

Certainly in Vista, task manager puts "Memory (Private Working Set)" as
the column title. Once you understand what the working set is, it's
clearer that task manager is working properly.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
Alvin Bruney [MVP]
5/8/2007 7:38:22 PM
thanks

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley


[quoted text, click to view]

Ben Voigt
5/15/2007 6:49:33 PM
[quoted text, click to view]

I think there's a faulty assumption, that unallocated memory isn't being
used for anything, and therefore should be leveraged to delay garbage
collection as long as possible. The missing piece of the puzzle, is that
the disk cache folks noticed the abundance of unallocated memory long ago,
and put it to really good use... which dramatically changes the cost-benefit
of delaying garbage collection.

Anything else you think comes into play here?

[quoted text, click to view]

AddThis Social Bookmark Button