Post by Surain ShenHi, Willy,
Thx a lot for ur reply, I do think it hits my question well:)
I had a winform app which consume much more memory than a similar app of
the competitor which looks written by VC. Compare the "VM Size" and "Mem
Usage" measure value in the task manager, my app always be twice over the
competitor's. As a result, the customer ask us to try decrease the memory
usage to a reasonable range, otherwise ...
Ask, the customer to remove some RAM from it's boxes, seriously why does an end user cares
about this?
Managed applications have a slightly larger memory footprint than comparable unmanaged
applications, the reason is the size of the CLR, it's managed heap and the size of the
loaded FCL (especially Windows Forms). This is something you can't get around, you need to
accept this, the larger footprint (because of the GC and the large heap) has numerous
advantages, the CLR makes better use of the available memory resources, so does the FCL
offer a rich set of API's, that means that you can build real complex applications in
managed code that don't consume much more (say the difference won't be larger than 10Mb)
memory space than a comparable native application, you get what you paid for, really.
Post by Surain ShenI had tried to do somethings such as releasing the reference, disposing,
and I even find anonymous method will increase memory usage a bit, and
etc., but it seems the memory usage only decrease a little...
Ok, my final question is how can I decrease the memory usage obviously?
Why, would you even try to do this, the OS will do it when there is a need for memory by
other applications.
Post by Surain ShenOf course, I and my customer known that .Net app will consume more memory
than the similar app which written by VC. We still hope to improve that
problem.
What problem? It's not difficult to consume a lot more memory when coding in a managed OO
language, it's up to you to watch your allocation algorithm and watch out for
over-consumption. Watch out for some OO designs, they tend to be the cause of
over-consumption, take care about Arrays and ArrayLists or container classes using Arrays as
backing store (or generic containers), don't use self expanding containers, pre-allocate
Arrays and List's whenever you can (you can most of the time). Otherwise stated, measure and
measure again. Use the CLR or another profiler, watch your allocation patterns, make sure
you apply a "dispose "pattern when needed, take special care about unmanaged code calls and
unmanaged memory resource usage. But keep in mind that you won't get (you don't need to) at
the level of unmanaged code, tell your customer that a similar application written in
assembly will probably use even less memory than the C equivalent, but it's price will be a
tenfold.
Willy.