views:

621

answers:

3

Hello

I have a simple C# 2008 application which displays a png-picture and handles some simple MouseEvents.

Although it's nothing complex, it uses at least 9.5-10 MB of memory (as shown in task-manager)

I've already disabled any type of error logging as well as I removed debug and trace symbols. "Optimize Code" is activated.

Is there any way to reduce this? Maybe with some options as native compiling of the framework (does this even exist for .NET?)

Any idea? Or is this just the price I have to pay for having the .NET-Framework?

Edit: 10 MB is not much, i know. But it's going to run on a Citrix Presentation Server (or XenApp as it is called now) which means that there are ~30 users on one server. 30 users * 10 MB = 300 MB only for this little application.

Thanks in advance and best regards

+10  A: 

Whatever you do, the CLR will have to be loaded in the process. 10MB is not too much memory and not all of 10MB is private memory (probably most of it is sharable). By the way, it's not like "if your simple app takes 10MB, making it as double as complex (memory-wise) will need twice the memory (basically, it's CLR's memory footprint.)

I just built a simple console application (for(;;);). "Resource Monitor" shows it takes ~2.5MB private memory and ~7MB sharable memory.

Mehrdad Afshari
10Mb is nothing to a modern system. Unless you're building something like an operating system, video game, or rdbms, the days of needing to keep your app to a few K are over.
Joel Coehoorn
@Joel: absolutely.
Mehrdad Afshari
You mean that video game devs try and reduce memory consumption? I remember being shocked a couple of years ago when a new game used 512MB of RAM!
Lucas Jones
person-b: video games are resource-intensive. It's very likely that the devs of the game you're talking about tried very hard to make it fit in 512MB.
Mehrdad Afshari
btw, what Mehrdad meant with "not all of 10MB is private memory" is that part of those 10MB are *shared* among several applications.
Lucas
A: 

You could look into something like static linking (http://www.codeproject.com/KB/cs/htmerge.aspx), but I'm not sure how that would affect the memory requirements.

Andrew Lewis
A: 

The problem with .net in this regard is that the memory is managed by the GarbageCollector, which will force collection of unreferenced objects only when it is running out of space.

You can also try manually triggering a garbage collection, see here: MSDN

What you can do particular is:

  • Try to keep references to objects as short as possible
  • reduce the number of used system libraries
  • take a look at .NET Bootstrapping
  • take a look at precompiling your assemblies via ngen.exe
  • use assembler :-) (just kidding)
Johannes Rudolph