Note that there are some explanatory texts on larger screens.

plurals
  1. POC# WCF - Client/Server - System.OutOfMemory Exception
    text
    copied!<h3>The Problem.</h3> <ul> <li>C# WCF Client/Server Application using Net TCP Binding (Publisher/Subscriber Pattern).</li> <li>Client-side keeps crashing with an <code>OutOfMemoryException</code>.</li> <li>When I run Task Manager along with the client, I can see the Memory Usage column increase until the application crashes.</li> <li>Intention is for multiple instances of the client to be running on separate machines.</li> </ul> <h3>Scenario</h3> <ul> <li>I have a client/server application.</li> <li>Publisher/Subscriber Design Pattern.</li> <li>On the server-side there are 6 dictionaries that make up a cache, each containing a custom object as a value.</li> <li>Each set of dictionary values gets updated every 5 seconds as part of a while loop.</li> <li>At the end of the 5 second loop, the 6 dictionaries are added to a datacontract object, each as a different data member.</li> <li>The data contract object is then sent over the wire to the client, where there are 6 more dictionaries.</li> <li>I then loop through each data contract dictionary, and either add to or update the contents of it's client-side equivalent, depending on whether the values already exist or not.</li> </ul> <h3>Summary</h3> <ul> <li>6 dictionaries server-side.</li> <li>6 serializable dictionaries in the data contract.</li> <li>6 bindable dictionaries client-side.</li> <li>WCF using Net TCP Binding to transport data over the wire.</li> </ul> <h3>Specification</h3> <ul> <li>C# .Net 3.5</li> <li>Client-side using one DevExpress form and 9 DX gridviews &amp; tab controls.</li> <li>Most of the custom objects containg a dictionary of "sub assets". - I have used a bindable dictionary for this property, which I imagine creates overhead when you have a few hundred objects (although I don't think using a serializable dictionary instead would make much difference, as they both contain the same code for serialization).</li> <li><p>Bindings on both sides are programmatically created once at the start and contain the same settings (see below).</p> <pre><code>NetTcpBinding netTcpBinding = new NetTcpBinding(SecurityMode.None); EndpointAddress endpointAddress = new EndpointAddress(EndpoindAddress); InstanceContext context = new InstanceContext(callbackinstance); netTcpBinding.MaxConnections = 5; netTcpBinding.MaxBufferSize = 2147483647; netTcpBinding.MaxBufferPoolSize = 2147483647; netTcpBinding.MaxReceivedMessageSize = 2147483647; netTcpBinding.ReceiveTimeout = TimeSpan.MaxValue; netTcpBinding.CloseTimeout = TimeSpan.MaxValue; netTcpBinding.TransferMode = TransferMode.Buffered; netTcpBinding.ListenBacklog = 5; DuplexChannelFactory&lt;ISubscription&gt; channelFactory = new DuplexChannelFactory&lt;ISubscription&gt;( new InstanceContext(this), netTcpBinding, endpointAddress); proxy = channelFactory.CreateChannel(); </code></pre></li> </ul> <h3>My Questions</h3> <ul> <li>How can I prevent the client memory usage from growing constantly?</li> <li>Would the memory usage on the client be significantly lower if I sent only Generic Lists of objects as opposed to serializable dictionaries?</li> <li>Have I setup my binding configurations correctly for this kind of implementation?</li> <li>Any other suggestions for fixing this memory problem would be greatly appreciated.</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload