0

I wrote a WCF (c#) Windows Service application, and it appears to me the windows service is leaking memory. The memory pressure, according to Windows, raised from the start of the windows service from 24 Gb till 44 Gb at the moment of the screen shot (30 hours later)

We have two problems;

  1. we tried to simulate the leakage using ANTS Memory Profiler, and we couldn't find the issue.
  2. WCF service itself is not leaking memory. The memory usage is 18 Gb (which is the same memory pressure as from the start of the service).

How can I investigate this problem? What is causing this high memory pressure?

Memory Usage

  • 2
    "the WCF service itself is not leaking memory." But obviously, it is. What do you mean with that statement? Can you take a heap snapshot and see what's there? – usr Mar 22 '14 at 22:46
  • Hi usr, The memory pressure, according to Windows, raised from the start of the windows service from 24 Gb till 44 Gb at the moment of the screen shot (30 hours later). As the server is only running my WCF service, it can only be caused by this application. – Jeroen van Onzen Mar 22 '14 at 22:59
  • 1
    Instead of reproducing the problem you can take a memory dump from server and analyze it "offline" i.e. in SciTech Memory profiler http://memprofiler.com/ . ANTS afaik doesn't support loading mem dumps. – Grzegorz Banczak Mar 22 '14 at 23:02
  • 1
    Personally, I would start cutting away code until it stops losing memory. There are three possibilities; a) there is a bug in WCF, b) you are managing to keep a link to objects that should, but cannot, be garbage collected, c) you are creating unmanage memory (via Marshal for instance) and not de-allocating it. – Meirion Hughes Mar 22 '14 at 23:45
  • Hi Grzegorz, thanks for the comments. The memory dump has the size of 18 Gb, probably missing the 20 Gb I am interested in. I tried to analyze the dump today, but I did not have any luck (out of memory exceptions, too large heap). I will try to set up a smaller test tomorrow. – Jeroen van Onzen Mar 23 '14 at 19:12
  • 1
    I had trouble with this, too. My problem was eventually solved. The biggest problem was that I had a shared reference to a data object passed into the WCF service from the hosting exe. Once I got rid of that, most of my memory problems went away. The other thing I did, too, was make all the objects in my service disposable. That, too, helped. – Brian Mar 24 '14 at 12:46
  • Hi Brian, was your service running on the same machine? Did you find any hypothese/diagnose on the internet to try this solution? – Jeroen van Onzen Mar 24 '14 at 14:18

1 Answers1

0

it appears to us, this is expected behaviour. We never saw this behaviour as the Development machines have less memory available. Only when 92 % - 95 % of the memory is 'occupied' a garbage collection is forced.

The reason we looked at this problem was because the processes were running more slow after a while.

Interesting reads: .NET application memory usage - high unused .NET and unmanaged memory and fragmentation

http://forum.memprofiler.com/viewtopic.php?f=2&t=4389

And put this book on my book shelf: http://download.red-gate.com/ebooks/DotNet/Under_the_Hood_of_.NET_Management.pdf

Thanks all,

Community
  • 1
  • 1