WCF Service Memory Leaks

Posted by Mubashar Ahmad on Stack Overflow See other posts from Stack Overflow or by Mubashar Ahmad
Published on 2010-05-12T11:39:36Z Indexed on 2010/05/12 11:44 UTC
Read the original article Hit count: 290

Filed under:
|
|

Dear Devs

I have a very small wcf service hosted in a console app.

[ServiceContract]
public interface IService1
{
    [OperationContract]
    void DoService();
}

[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall)]
public class Service1 : IService1
{
    public void DoService()
    {

    }
}

and its being called as

using (ServiceReference1.Service1Client client = new ServiceReference1.Service1Client())
{
    client.DoService(new DoServiceRequest());
    client.Close();
} 

Please remember that service is published on basicHttpBindings.

Problem

Now when i performed above client code in a loop of 1000 i found big difference between "All Heap bytes" and "Private Bytes" performance counters (i used .net memory profiler). After investigation i found some of the objects are not properly disposed following are the list of those objects (1000 undisposed instance were found --> equals to the client calls)

(namespace for all of them is System.ServiceModel.Channels)

HttpOutput.ListenerResponseHttpOutput.ListenerResponseOutputStream
BodyWriterMessage
BufferedMessage
HttpRequestContext.ListenerHttpContext.ListenerContextHttpInput.ListenerContextInputStream
HttpRequestContext.ListenerHttpContext 

Questions Why do we have lot of undisposed objects and how to control them.

Please Help

© Stack Overflow or respective owner

Related posts about wcf

Related posts about memory-leaks