How can I decrease size of mem usage.

G

Guest

Hi,

I've written a somewhat large program over the years (70.000 lines of code).
When compiling the program I get a 2MB exe file. When running this program I
get an corresponding image in the task manager showing a 40 MB memory
allocation . Yes, the program allocates memory dynamicaly, but no where near
this amout of memory. Of cause I expect some .net stuff is probably also
contained in this allocation. However, if reinstantiating the program several
times, every instance (shown in the task manager) is showing a memory usage
of around 40-50 MB. I thought that code was shared in such scenarios in order
to save memory space.

Q: What si happening in .net?

Q: Is there any flag/compiler option that I can check/uncheck to a smaller
memory allocation.

Best regards
Jesper, Denmark
 
B

Bela Istok

Hello, this is not easy to respond, if you have a lot of memory the
application will use as much memory as his can (for the optimization, and
fast loading). Example: I have an app that have almost 500.000 Lines of
code, If I run the code in a machine that have 2 GB of memory the
application uses More that 150 MB, but if I run the same App in a machine
with 256 or 128 MB of ram the app run with a 35 MB of ram. In each case the
application run well, in both machines.

PD: The Compiler, don't allow you to do an intensive memory optimization,
that is because the runtime handles the memory for the applications not the
compiler.

Regards,

Bela Istok
 
W

Willy Denoyette [MVP]

Jesper said:
Hi,

I've written a somewhat large program over the years (70.000 lines of code).
When compiling the program I get a 2MB exe file. When running this program I
get an corresponding image in the task manager showing a 40 MB memory
allocation . Yes, the program allocates memory dynamicaly, but no where near
this amout of memory. Of cause I expect some .net stuff is probably also
contained in this allocation. However, if reinstantiating the program several
times, every instance (shown in the task manager) is showing a memory usage
of around 40-50 MB. I thought that code was shared in such scenarios in order
to save memory space.

Q: What si happening in .net?

Q: Is there any flag/compiler option that I can check/uncheck to a smaller
memory allocation.

Best regards
Jesper, Denmark


First of, there a a lot of significant memory counters available, what kind of memory
consumption are you talking about?
Second, the size of the exe file has strictly nothing to do with the memory consumption when
the program runs.
A 1KB exe can consume Giga bytes of memory when it runs, all depends on what the program is
doing, what kind and how many objects are there allocated at any time.
Note also that your exe is only (a small) part of the assemblies and DLL's loaded when the
program runs. If this is a windows forms application some more memory is taken by the forms
library and the higher number of objects allocated during forms initialization. Also take
into account that every managed program has at least 3 or 4 threads, that means 3 (4) x 1MB
for stack allocation (committed). And the GC heap starts with a allocated (Reserved) size of
32 MB. So, 40MB is really nothing to worry about.

Willy.
 
G

Guest

Hi,

Are you keeping references to instances you dont longer needs?

IIRC the minimal memory ocupation of an application is from 15 -+4

So yours is not that far off.

In any case , use a memory profiler to see how the memory is being allocated
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top