Friday, November 21, 2008
Worries Over Task Manager

If you make a simple console app that just writes a line to the cmd window and run it you will notice Task Manager showing that app as taking up 3 -7 MB of RAM.

If you start a brand new C# or VB gui app with a single form and put NO code in it and no controls on it, but just compile (release settings) it as a form that does and has nothing then when you run it you will see that that form alone is taking up 7 - 10 or more MB of RAM.

If you minimize either of these apps then restore them you will see the memory usage drop down to a far more realistic level.

This is not GC stuff, since all Win32 apps do the same thing when you start them ... just not so drastically.

Like you, I remember seeing this in the betas but in the back of my mind I figured it would be "fixed" in the final release. And while I read Richters' articles on the GC and "knew" in an acedemic sense that resource usage was going to appear differently under .net, when it came down to hearing the deployment team say "geeze, you're app is taking up too much memory" it scared me enough to make me need some real-world reassurance.

Thanks to lots of folks on various NGs and more testing, I've been reassured. Even though it is scary to see huge amounts of memory being allocated, under .net it is not necessarily leading to Out of Memory errors...

From Mike McIntyre on the public.framework:

"I have not had any memory issues with the Win Forms applications I have developed. But I have seen postings expressing concern about how much memory .NET applications consume and I became more and more curious. The postings often express concern that even a simple Hello World application may use 7.5 to 12 mb of memory.

I asked a few folks at Microsoft about this. I was told that if the memory is not being used, an application may grab a good sized chunk of it. But, unless it really needs it, the application will not be so 'greedy' (my own words) as available memory starts to get used up.

I performed an experiment. I created the Hello World application, then opened it 51 times. On my two year old Dell Latitude, with 500 mb of memory, running XP - here is what happended:

At first instance of the Hello World app took 7.5 mb of memory. Until I got to around 45 instances, each instance I opened took another 7.5 mb of memory. Then, with memory getting tight it start using less and less for each instance I opened.

The last five instances of Hello World opened and ran fine in 1.7 mb of memory. Still not like VB6 but real close.

I right clicked on the group and chose close group. Very rapidly each closed in turn. In 30 seconds they were all closed and available memory was back to where it was when I started.
"

And from a dialog with Alan Pretre:

" [me:] So are you leading me to the water of these not being worrisome because the GC will eventually be collecting bytes down to the leanest weight? If so, is there some way to force task Managers' display to get the hint :)? I want to believe that something like that will happen in the real world but I've got a form with a small number of controls that loads as 30MB in TaskMgr and it's scary.

[Alan:] Yes, I was trying to lead you there . The GC world is a paradigm shift that takes some getting used to. Truth is, on a machine with lots of RAM alot of it sits around empty. The GC says, what the heck, I'll release later. If there is a demand on RAM from elsewhere, it will kick in and do its thing. But in the mean time, it appears that consumption goes up and up...
"

Note that last line because it will freak you out: "it appears that consumption goes up and up." We made a little test app that just showed a form with an animated GIF and watched TM's memory usage counter steadily rise as the form sat there.

Bottom line: Our tests mirror those that Mike stated above, in tests of many apps (including a "in-the-real-world" app that loads in at 23MB to start) the usage does come down as the box is in need. However, while we're ready to have some faith (what else can we do?) we'd sure like the GC to be faster on the collection at startup because as-is it's like playing Quake and only seeing the health packs when you're just about dead. That's fun for gaming, but corporate development should not be full of such worries.

Robert Smith
Kirkland, WA

added September 2002


Print  

pagecomment
  Add Comment



Submit Comment
  View Ratings
50.00%0
40.00%0
30.00%0
20.00%0
10.00%0

Number of Comments 0 , Average of Ratings
  View Comments
No comment.


Privacy Statement  |  Terms Of Use
Copyright 2008 by Robert C. Smith