开发者

How can I work out why my .net service is chewing up memory?

We have a .net c# service that when tured on is chewing up more and more memory. It has one 'Service' derived class that bas开发者_如何学运维ically creates other objects that encapsulate individual functionality that the service is meant to support. Im thinking that maybe I am creating an object and its not getting garbage collected due to a programming error.

Anyone know the best way to find out what is going on without setting break points?


You can use memory profilers like memprofiler, ants profiler, and this question can also help What Are Some Good .NET Profilers?

They give you a good look at the objects being created, generation they are in, memory they are using etc. You can, most of the times, narrow down the problem using profilers.


best way is to run Performance Profiler that comes in Visual Studio. It allows you to see your object lifetime.

This link might be helpful


You must be using objects that need to be disposed.
Some good examples are streams and web clients.


Create a text log and log everything that happens and work from there. Especially with a service this is the easiest way to find out what can be going wrong. Just print out events, the states of objects and their properties.

Maybe you can find something out that way.

Good luck to you


Use the CLR Profiler. It's a profiler specifically for examining memory usage.

1.1 Profiler

2.0 Profiler

4.0 Profiler


You need to use memory profiler to see what objects are causing memory leaks. I use this one for such cases: http://www.jetbrains.com/profiler/


Open task manager and watch the memory

Wrap each major piece of execution in a Class (here i used a BLL)

then call from the BLL

Then Try wrapping each top level piece in a using statement one at a time

using ( TheBll bll = new TheBll)
            {
                bll.ProcessStuff();
            }

This makes most everythign deallocate after the code is done, makes for easier memory cleanup.

then re run, if the memory stops going up, or slows down, you've found a cuplrit, go deeper into that one.

If you are happy with the results after you've wrapped all your top level calls with using statements, you might be done before you dig deeper. (Though you should dig, just to learn what's really wrong when you're not in a hurry)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜