C # 2k8 reduces memory usage (simple app takes 10MB)

I have a simple C # 2008 application that displays a png image and handles some simple MouseEvents.

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

I've already turned off error logging and also removed the debug and trace symbols. "Optimize Code" is activated.

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

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

Edit : 10 MB is not very good, I know. But it will run on Citrix Presentation Server (or XenApp as it is being called now) which means there are ~ 30 users on one server. 30 users * 10 MB = 300 MB for this small app only.

Thanks in advance and best wishes

+2


source to share


3 answers


Whatever you do, the CLR will have to be loaded into the process. 10 MB is not too much memory, and not all 10 MB is private memory (perhaps most of it is shared). By the way, this is not like "if your simple application is 10MB, which makes it twice as difficult (from memory) it will need twice as much memory (basically, it's a CLR memory area)."



I just created a simple console app ( for(;;);

). Resource Monitor shows that it requires ~ 2.5 MB of private memory and ~ 7 MB of available memory.

+10


source


You can look at something like static linking ( http://www.codeproject.com/KB/cs/htmerge.aspx ), but I'm not sure how this will affect the memory requirements.



0


source


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

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

What you can do is:

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


source







All Articles