0

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?

Exitos
  • 29,230
  • 38
  • 123
  • 178
  • Are you *sure* (as in *really sure*) that the service is eating memory? [Anatomy of a “Memory Leak”](http://stackoverflow.com/questions/104/anatomy-of-a-memory-leak) is a good starting point for investigating the cause. – Fredrik Mörk Jun 27 '11 at 14:31
  • In task manager the memory is going up. When it is turned on its at 17k after 3 days its at 5GB. Can I be any more sure? – Exitos Jun 27 '11 at 14:52

7 Answers7

1

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.

Community
  • 1
  • 1
ata
  • 8,853
  • 8
  • 42
  • 68
0

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

Bek Raupov
  • 3,782
  • 3
  • 24
  • 42
0

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

Vercas
  • 8,931
  • 15
  • 66
  • 106
  • Yes I think that your right Im creating objects but I need to identify which objects. – Exitos Jun 27 '11 at 14:54
  • Well, there's nobody better at identifying disposable objects than a human. Look at the suspicious classes you use and see if they have a `Dispose` method. Maybe the first step in identifying it is to tell us what does the service do. If it is a web service, you might have `WebClient`s undisposed, or `NetworkStream`s from web responses... – Vercas Jun 27 '11 at 20:22
0

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

stuartmclark
  • 1,203
  • 13
  • 22
0

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

1.1 Profiler

2.0 Profiler

4.0 Profiler

Brian
  • 25,523
  • 18
  • 82
  • 173
0

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/

Stanislav Berkov
  • 5,929
  • 2
  • 30
  • 36
0

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)

Eric Brown - Cal
  • 14,135
  • 12
  • 58
  • 97