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

2019-09-06 15:14发布

We have a .net c# service that when tured on is chewing up more and more memory. It has one 'Service' derived class that basically 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?

7条回答
Melony?
2楼-- · 2019-09-06 15:57

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/

查看更多
姐就是有狂的资本
3楼-- · 2019-09-06 16:01

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)

查看更多
叛逆
4楼-- · 2019-09-06 16:04

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

查看更多
我命由我不由天
5楼-- · 2019-09-06 16:11

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

1.1 Profiler

2.0 Profiler

4.0 Profiler

查看更多
The star\"
6楼-- · 2019-09-06 16:14

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

查看更多
Fickle 薄情
7楼-- · 2019-09-06 16:18

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.

查看更多
登录 后发表回答