Memory Usage of .NET programs.

  • Thread starter Thread starter Daniel Harper
  • Start date Start date
D

Daniel Harper

I just decided to try to switch to .NET programming. Just
as a test for the pros/cons I decided to see about the
differences im memory consumption.

I wrote an MFC application and that took up a little over
2 Meg in the debugging environment. Then I decided to
just try a Visual C++.NET form without any controls or
extra code in it. The form just by itself took up 15 megs
of memory! Even after changing it to release mode
the .NET form took up 12 megs of memory.

Is this common for .NET applications to take up more
memory? Or is it just a compiler setting that I am
missing?
 
Daniel Harper said:
I wrote an MFC application and that took up a little over
2 Meg in the debugging environment. Then I decided to
just try a Visual C++.NET form without any controls or
extra code in it. The form just by itself took up 15 megs
of memory! Even after changing it to release mode
the .NET form took up 12 megs of memory.

Try minimizing your form and then maximizing it again. You'll notice that
the memory consumption magically drops from 12Mb to 1 or 2Mb.

Also, note that .NET uses a garbage collector and MFC applications do not.
MFC applications always free their memory as soon as possible, even when
it's not necessary (if there's plenty of memory left). The .NET GC waits
with freeing memory until absolutely necessary, so a typical .NET
application will consume more memory compared to a typical MFC application.

Regards,
Pieter Philippaerts
Managed SSL/TLS: http://www.mentalis.org/go.php?sl
 
Back
Top