I hit issue that my ASP.NET 4 MVC 2 + WCF application utilize lots of memory in Windows 2008 64-bit application during the load testing where it will use up almost all the available memory (8 GB) after few minutes run (we did have few worker process running).
After profiling using ANTS Memory Profiler it was showing few interesting outcome:
Based on item no 1 above, I tested some application to test whether the issue is due to our application or WCF. The test application just load XML data (about 300KB) to dataset in a multithreading application. When the logic is stored in EXE program, the application use only 200 KB (additional 120 KB from beginning with 40 KB for unused memory) managed memory from 24 MB private bytes after finish (which is acceptable); but when the logic is hosted in WCF, the application uses 66 MB managed memory (additional 61 MB from beginning with 64 MB free/unused managed memory). So it seems that WCF / ASP.NET is the one that causing the memory to increase a lot).
Appreciate your advise on the question above.
Thanks in advance,
Willy
WCF uses temporary buffers to process messages. What you perceive as a memory leak may be temporary buffers that haven't been collected yet.
To avoid creating new buffers all the time WCF uses BufferManager to reuse buffers, up to the limit specified by maxBufferPoolSize(link to the element here), which by default is 512KB. Any requests beyond this limit cause new buffers to be created that are never reused and have to be garbage collected.
Another option to check is maxBufferSize, which limits the maximum buffer size that can be returned by the BufferManager. Larger buffers are not pooled and have to be garbage collected. If you use large messages, you may be able to reduce the temporary buffers by increasing this property.
Try increasing maxBufferPoolSize
to see if you can reduce memory usage. I would strongly advice though NOT to max it, because buffers from the pool are never released until the app-domain (ie the Application Pool) recycles. A period of high traffic could cause a lot of memory to be used and never released.
Regarding the "unmanaged memory leak" I had such a case sometime ago and after some digging it was an ADO.NET provider - fixed this with an updated version :-)
As for the rest - try putting this into the config:
<Configuration>
<runtime>
<gcServer enabled=“true“ />
</runtime>
</Configuration>
Other than this there is nothing special about WCF IMHO... there could be a memory leak like in any .NET app (for example event handler and static handlers/objects can create memory leaks when not unsubsrcibed properly)...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With