发信人: LodossWar (sleepycat), 信区: DotNet
标 题: About memory usage of .Net program
发信站: Unknown Space - 未名空间 (Thu Oct 23 11:55:15 2003) WWW-POST
My words: I have tested what the paper said with my own programs. It is true
that simple WinForms will const you more than 10M. And when you start two
instances of a same program, it will cost double memory, which is 20M.
I know the way to save memory for 2-instances case. Provide your own loader of
IL classes and let those two instances share libraries. This is the way I used
in Java, which will save you lots of memory. But this way sacrifice security
feature of "sandbox". So use this trick carefully. :)
Q I have a question about the memory footprint in an application built using
the Microsoft® .NET Framework. I built a little sticky notes utility as
part of a learning exercise in a class on coding techniques for Visual
Basic® .NET. It was a simple program that had one small hidden form and a
Notify icon, but it allocated 12MB of memory! That wouldn't matter for a
robust data-driven application, but is there any way to reduce the memory
footprint for a small Visual Basic .NET utility?
A To test your problem, I created a simple Visual Basic .NET Windows®
Forms application that had no event code or controls. I ran the program and
looked in Task Manager at the memory utilization. The memory used ranged from
7,980KB to 8,020KB, with the default settings for the project in Visual
I recompiled the application in Release mode and checked its memory again.
It then showed 6,328KB, so just changing to Release mode reduced the memory
footprint considerably. The file size of the .exe also dropped, from 8KB to
Next, I added two textboxes and a button control and recompiled and ran the
application. This resulted in an application size of 6,724KB. At this point,
the total memory size of the application was quite small. I decided to create
a similar C# application and check that in order to compare. The C#
application with no controls used 6,200KB, so there was very little difference
between a C# or Visual Basic .NET application, at least at first glance.
I thought that Windows Forms would add a bit of overhead, so I created a
simple console application that I could run at the command prompt. This
application would simply write "Hello World" and wait for the user to press a
key. No Windows Forms or other sophisticated code was involved. Running this
application compiled with Debug resulted in a 4,312KB footprint. This simple
console application showed a size of 3,748KB when compiled in Release mode.
So, it appeared that Windows Forms added a good bit of size to the
application. That actually makes sense since adding GUI support to any
application naturally should add some overhead. It's pretty clear that the
Microsoft .NET Framework and Windows Forms architecture was playing a major
role in the memory used by the console application.
Before doing any more experiments, I thought it would be good to get more
information on memory usage, which became the answer to the next question.
※ 修改:·LodossWar 於 Oct 23 11:55:15 修改本文·[FROM: 151.201.]
※ 来源:．Unknown Space - 未名空间 mitbbs.com．[FROM: 151.201.]