Bug 40039 - Memory leaks in WCF Duplex Channel in Mono
Summary: Memory leaks in WCF Duplex Channel in Mono
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: WCF assemblies (show other bugs)
Version: 4.0.0
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-04-01 08:21 UTC by Ashish
Modified: 2016-12-06 16:19 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 40039 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

Description Ashish 2016-04-01 08:21:07 UTC
I am Creating a Server Client Application in which I am using TCP binding with Duplex Channel There is a method Poll() in Server App and CallBack method OnPollBack() in Client app. I am calling Poll method by client app in 100 millisecond but in half an hour I am getting out of memory exception. This Duplex Tcp binding takes 10 mb in around 200 hits of Poll method now What I do there is a lot of memory leak in Tcp binding of wcf..


Server Code:

public class SipServer { private ServiceHost sipHost; public void HostServer() {

        var address = @"net.tcp://localhost:44000/SipPhone";

        var sipPhImpl = new SipPhoneImpl();
        sipHost = new ServiceHost(sipPhImpl);

        var tcpBinding = new NetTcpBinding(SecurityMode.None);
        tcpBinding.ReceiveTimeout = TimeSpan.MaxValue;
        tcpBinding.SendTimeout = TimeSpan.MaxValue;

        var sipEndPoint = sipHost.AddServiceEndpoint(typeof(ISipPhone), tcpBinding, address);
        sipHost.Open();
    }

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)]
    public class SipPhoneImpl : ISipPhone
    {

        private ISipPhoneCallback _phCallBack = null;
        private bool disposed = false;


        public int Poll(bool sendBack, string pollStr)
        {
            if (sendBack)
            {
                try
                {
                    ISipPhoneCallback cb = _phCallBack != null
                                                    ? _phCallBack
                                                    : OperationContext.Current.GetCallbackChannel<ISipPhoneCallback>();
                    if (cb != null)
                    {
                        cb.OnPollBack(pollStr);
                    }
                }
                catch (Exception ex)
                {

                    return 1;
                }
            }

            return 0;
        }

    }
}


Client Code:

public class UcomClient { private ISipPhone m_sipPhone; public void CreateClient() {

        var hostAddress = @"net.tcp://localhost:44000/SipPhone";

        var tcpBinding = new NetTcpBinding(SecurityMode.None)
        {
            ReceiveTimeout = TimeSpan.MaxValue,
            SendTimeout = TimeSpan.MaxValue

        };

        InstanceContext cbContext = new InstanceContext(new UCOMSipCallBack());
        var spFactory = new DuplexChannelFactory<ISipPhone>(cbContext,tcpBinding, hostAddress);
        m_sipPhone = spFactory.CreateChannel();

    }

    public int Poll(bool sendBack, string pollStr)
    {
        try
        {
            return m_sipPhone.Poll(sendBack, pollStr);
        }
        catch (Exception ex)
        {

            return 1;
        }
    }
}

public class UCOMSipCallBack : ISipPhoneCallback
    {
        public void OnPollBack(string pollStr)
        {
            Console.WriteLine(pollStr + " : " + DateTime.Now);

        }
    }




Interfaces:

[ServiceContract(SessionMode = SessionMode.Required, CallbackContract = typeof(ISipPhoneCallback))] public interface ISipPhone { [OperationContract(IsInitiating = true)] int Poll(bool sendBack, string pollStr); }

public interface ISipPhoneCallback { [OperationContract(IsOneWay = true)] void OnPollBack(string pollStr);

}