How to trace the memory in c#?

N

Nick

hi, all
In c#, we know it has garbage collection. I am think is there anyway we
can know an exe, how many thread in this exe, when the memory gets
allocated, and when it gets destoryed. Becuase I believe our program
has a memory issue. From the window task manager, we can see, the
memory just gets bigger and bigger,and it never goes down. So I am
thinking how to trace this kind of problem. The program is a c# windows
service.

Thanks.
 
N

Nicholas Paldino [.NET/C# MVP]

Nick,

What you see in the Task Manager is actually standard behavior for a
..NET app. Chances are you do not have a memory leak.

The reason you see that in the task manager is because of the runtime,
and the number of objects you create. It WILL climb. However, that number
will fluctuate up and down over time.

Hope this helps.
 
P

Pete Davis

I find that the garbage collector in C# isn't always timely. Particularly in
busy applications.

You might find if you do a periodic GC.Collect(), this memory will go down.
I've had some apps that hardly ever freed the CPU up and the garbage
collector pretty much refused to clean up even when the system started
paging so bad that the app came to a crawl. Adding a periodic GC.Collect()
fixed the problem.

You can get a trial version of the Sci Tech .NET Memory Profiler here:

http://www.scitech.se/memprofiler/

It's excellent and will show you what's being allocated a freed.

Pete

That said, there is the possibility of leaks in .NET code. Ther
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi Nick,

Nothing weird here, as you need memory the framework will request it to the
OS , and it will keep it later just in case, only when the OS needs it back
it's returned to the OS.

Of course the above is an over simplification of the process but you should
get the idea.

Now, I do remember I tried a .NET memory profiler :
http://www.scitech.se/memprofiler/ you can give it a try.

cheers,
 
J

John Murray

You can get some information on collections ..etc.. from performance
profiler. If you need more detail, you can also use clr profiler (it's
free)
 

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