Finding a memory leak in C#???

M

Mark Steele

I'm working on a project where we collect data and store it in ArrayLists.
When the size of the ArrayList gets to 100K elements we prune it back down
to 50K.

I let my application run over the weekend and Windows Task Manager shows
that the application is using 500,000K memory for my application.
I figure that I'm doing something wrong so I download a trial copy of
Borlands OptimizeIt profiler and run the application again. Windows Task
Manager again shows that I have 500 Megs of application memory, but the
profiler will only account for a little over 12 Megs total!

Ok, so maybe something is wrong with Borlands profiler so I get Microsofts
CLR profiler and launch my application but tell it to not collect data just
yet. I'm hoping that this will give me a baseline for the overhead of the
CLR. Windows Task Manager shows 85 megs (ouch!) so I have my application
start collecting data - it quickly jumps to 100 megs and continues to grow.
The CLR show an allocation graph and reports a grand total of 2.3 megs (much
less than the 15 meg jump in memory that the Task Manager shows). I continue
to let the application run and when the task manager shows 500 megs the CLR
profiler shows the familiar 12.4 megs grand total that OptimizeIt reports (I
had to manually add up the OptimizeIt total 'cause I don't know how to get
it to report a grand total yet).

If I let this application continue it will eventually run out of virtual
memory and stop.

Both profilers show that the elements in the ArrayList account for about 1.8
megs (each item is 24 bytes) and that is the largest allocation in both
number of objects and total memory.

Where is all this extra memory going?

Is there a tool that will dive deeper into the CLR and let me know who or
what is sucking up nearly 400 megs of memory that the Task manager is
reporting but the profilers don't see?

Thanks for any help,
-Mark
 
J

Jochen Kalmbach

Mark said:
I let my application run over the weekend and Windows Task Manager
shows that the application is using 500,000K memory for my
application. I figure that I'm doing something wrong so I download a
trial copy of Borlands OptimizeIt profiler and run the application
again. Windows Task Manager again shows that I have 500 Megs of
application memory, but the profiler will only account for a little
over 12 Megs total!

1. Please use "Performance Monitor" to see the "correct" values
(".NET-CLR Memory | commited bytes" and "Process | Private bytes")

If the .NET-Memory is really 500 MB, then use a third party tool like
Rational Purify to find the "leak" (or the references)

If the .NET-Memory far less than 500 MB, then you are using some kind of
"old fashion" DLLs or COM. Then you have a (real) memory leak in one of
your InterOp-DLLs/COMs.


--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp

Do you need daily reports from your server?
http://sourceforge.net/projects/srvreport/
 
C

Chad Myers

Mark said:
I'm working on a project where we collect data and store it in ArrayLists.
When the size of the ArrayList gets to 100K elements we prune it back down
to 50K.

I let my application run over the weekend and Windows Task Manager shows
that the application is using 500,000K memory for my application.
I figure that I'm doing something wrong so I download a trial copy of
Borlands OptimizeIt profiler and run the application again. Windows Task
Manager again shows that I have 500 Megs of application memory, but the
profiler will only account for a little over 12 Megs total!

Ok, so maybe something is wrong with Borlands profiler so I get Microsofts
CLR profiler and launch my application but tell it to not collect data just
yet. I'm hoping that this will give me a baseline for the overhead of the
CLR. Windows Task Manager shows 85 megs (ouch!) so I have my application
start collecting data - it quickly jumps to 100 megs and continues to grow.
The CLR show an allocation graph and reports a grand total of 2.3 megs (much
less than the 15 meg jump in memory that the Task Manager shows). I continue
to let the application run and when the task manager shows 500 megs the CLR
profiler shows the familiar 12.4 megs grand total that OptimizeIt reports (I
had to manually add up the OptimizeIt total 'cause I don't know how to get
it to report a grand total yet).

If I let this application continue it will eventually run out of virtual
memory and stop.

Both profilers show that the elements in the ArrayList account for about 1.8
megs (each item is 24 bytes) and that is the largest allocation in both
number of objects and total memory.

Where is all this extra memory going?

Is there a tool that will dive deeper into the CLR and let me know who or
what is sucking up nearly 400 megs of memory that the Task manager is
reporting but the profilers don't see?

Thanks for any help,
-Mark

In addition to the other replies you just saw, please note that Task
Manager reports memory usage in a funny way. Basically, applications can
request memory from the OS all day long, but until they actually use it,
it's not really considered "used". Task Manager will report what the
application has requested, from what I understand. So .NET is a little
liberal about how it requests memory, but it's spot-on with how it uses
it. So .NET may have requested to use 500MB or even 2GB, but it may only
be using 12MB. Please do not use Task Manager as a performance
monitoring tool.

Use PerfMon like Jochen recommended.

-c
 

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