470,591 Members | 2,174 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,591 developers. It's quick & easy.

.NET eats memory.


I am trying to optimize my C# program, but no matter what I try the
application keeps eating memory. I verified all the references and even got
special software to count references. I made sure all the reference count
reaches zero for all the objects that are no longer used. I also call
Dispose as much as possible. Regardless, the memory is not freed. Even if I
force the GC, some memory gets freed but not much.


I believe the memory is taken by the framework itself. Connection pool,
Thread pool or some other resources the framework uses. I have no way to
know where all the memory is, and therefore I have no way to optimize my
application.

Any ideas how I can control the memory under the framework?

Jul 19 '05 #1
2 3106
"Mike Peretz" <m_******@sympatico.ca> wrote in
news:xd******************@news20.bellglobal.com:

I am trying to optimize my C# program, but no matter what I try
the application keeps eating memory. I verified all the
references and even got special software to count references. I
made sure all the reference count reaches zero for all the
objects that are no longer used. I also call Dispose as much as
possible. Regardless, the memory is not freed. Even if I force
the GC, some memory gets freed but not much.

I believe the memory is taken by the framework itself.
Connection pool, Thread pool or some other resources the
framework uses. I have no way to know where all the memory is,
and therefore I have no way to optimize my application.

Any ideas how I can control the memory under the framework?


Mike,

How are you measuring the memory usage?

If you are using Task Manager (TM), then realize that TM doesn't seem
to give an accurate measure of the memory a .Net app uses. In fact,
AFAIK, the algorithm used by TM to calculate memory usage is not
published. This means there's no way to know what the number
reported by TM actually reflects. Total physical memory used? Total
virtual memory used? Both? Maybe it's the *anticipated* amount of
memory TM thinks a .Net app will use, and not the actual memory
usage. Your guess is as good as mine.

If you are developing a desktop C# app, try this experiment. Open
TM. Run your app. Note the memory useage reported by TM. Minimize
your app. Note the memory useage again. Restore your app. Note the
memory usage. On my system, with a small C# app, I get readings like
this:

- app startup = 9.6 MB
- app minimize = 608 K
- app restore = 2.5 MB

This gives me the impression that instead of reporting the actual
memory usage of my .Net app, TM is making some kind of complicated
guess as to how much memory my app *might* need. Again, there's no
way to tell for sure...

My approach is to ignore TM's data and use debugging and profiling
tools instead. .Net comes with several performance counters, and
there are third-party apps - both free and commercial - that can
provide much more accurate info than TM.
Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Jul 19 '05 #2
..NET Applications seize all of the memory available to them in 1.x versions
of the .NET Framework. However, if another application needs memory, the
framework gladly gives it up (Hence the small memory footprint when an
application is minimized). The memory footprint of a minimized application
is a more accurate analysis of the amount of memory that your application is
using than the large amount of memory consumed when an application is
maximized.

What memory footprint are you targetting? Are you running into a performance
problem because of the application's large memory usage?

-keen
"Mike Peretz" <m_******@sympatico.ca> wrote in message
news:xd******************@news20.bellglobal.com...

I am trying to optimize my C# program, but no matter what I try the
application keeps eating memory. I verified all the references and even got special software to count references. I made sure all the reference count
reaches zero for all the objects that are no longer used. I also call
Dispose as much as possible. Regardless, the memory is not freed. Even if I force the GC, some memory gets freed but not much.


I believe the memory is taken by the framework itself. Connection pool,
Thread pool or some other resources the framework uses. I have no way to
know where all the memory is, and therefore I have no way to optimize my
application.

Any ideas how I can control the memory under the framework?


Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.