PorcupineRending
PorcupineRending

Reputation: 1525

Tracking down a memory leak in a WCF Service

I have a WCF service that's currently hosted in IIS7 using .NET 4.0 in Classic mode. The service typically hums along between 250 and 400mb which is reasonable since the size of the database it's connected to is only about 300mb. Along with the memory usage the CPU usage stays between 0% and 15%. Then randomly the CPU and memory usage will essentially spike dramatically. RAM usage will go up to the phsyical memory limit (which on this EC2 instance is 1.7GB) and CPU will peak out at 100% for a bit then return to between 25% and 50%. After a few minutes the memory usage and CPU usage will drop back down to normal.

Does anyone have any idea what might be causing this? If not is there a good way to track down the issue? I've used PerfMon to look at the usage but I can't find a good way to track down where all that memory is actually being used in the WCF service. Any suggestions are appreciated.

Upvotes: 1

Views: 7230

Answers (2)

PorcupineRending
PorcupineRending

Reputation: 1525

Downloaded a profiler as you guys suggested. Turns out it wasn't something I was doing but there is a bug in how the search feature in the AE.Mail library (which I'm using) works which was causing a massive bloat in memory every 5 minutes. The one I used was Red-gate's which was awesome, thanks to everyone who input advice.

Upvotes: 0

atlaste
atlaste

Reputation: 31106

Sounds to me like you're not closing the connections properly. When you're using WCF, always note that connections implement IDisposable - if you don't use it, the connections will linger and the data will be stored. Use 'using' properly and you'll probably solve the issue.

Second, it might just mean you're using the PerSession mode. If you're using sessions, they will be stored of course :-) Also, there are some known bugs in WCF that can cause this. The most notable involves 'Singleton' mode; change that to 'PerCall' and it might solve your issue altogether.

I've seen a couple of cases where this leads to memory leaks.

As for profiling, I'm a big fan of Red-gate / ANTS, but there are other profilers around as well.

Upvotes: 3

Related Questions