C#WCF-客户端/服务器-System.OutOfMemory异常 [英] C# WCF - Client/Server - System.OutOfMemory Exception

查看:355
本文介绍了C#WCF-客户端/服务器-System.OutOfMemory异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 使用Net TCP绑定(发布者/订阅者模式)的C#WCF客户端/服务器应用程序.
  • 客户端始终崩溃并显示OutOfMemoryException.
  • 与客户端一起运行任务管理器时,可以看到内存使用情况"列增加,直到应用程序崩溃为止.
  • 意图是使客户端的多个实例在不同的计算机上运行.
  • C# WCF Client/Server Application using Net TCP Binding (Publisher/Subscriber Pattern).
  • Client-side keeps crashing with an OutOfMemoryException.
  • When I run Task Manager along with the client, I can see the Memory Usage column increase until the application crashes.
  • Intention is for multiple instances of the client to be running on separate machines.
  • 我有一个客户端/服务器应用程序.
  • 发布者/订阅者设计模式.
  • 在服务器端,有6个字典组成一个缓存,每个字典都包含一个自定义对象作为值.
  • 每组字典值都会在while循环中每5秒更新一次.
  • 在5秒循环的结尾,将6个字典添加到一个datacontract对象中,每个字典都作为不同的数据成员.
  • 然后将数据合同对象通过电线发送到客户端,那里还有6个字典.
  • 然后,我遍历每个数据协定字典,并根据其值是否存在来添加或更新其等效于客户端的内容.
  • 6个词典在服务器端.
  • 数据合同中的
  • 6个可序列化词典.
  • 6个可绑定的词典客户端.
  • WCF使用Net TCP绑定在网络上传输数据.
  • 6 dictionaries server-side.
  • 6 serializable dictionaries in the data contract.
  • 6 bindable dictionaries client-side.
  • WCF using Net TCP Binding to transport data over the wire.
  • C#.Net 3.5
  • 客户端使用一个DevExpress表单和9个DX gridviews&标签控件.
  • 大多数自定义对象包含子资产"的字典. -我为此属性使用了可绑定的字典,我想当您有数百个对象时会产生开销(尽管我不认为使用可序列化的字典会产生很大的不同,因为它们都包含相同的序列化代码)
  • 两侧的绑定都是从头开始以编程方式创建的,并且包含相同的设置(请参见下文).

  • C# .Net 3.5
  • Client-side using one DevExpress form and 9 DX gridviews & tab controls.
  • 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).
  • Bindings on both sides are programmatically created once at the start and contain the same settings (see below).

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<ISubscription> channelFactory =
   new DuplexChannelFactory<ISubscription>(
          new InstanceContext(this), 
          netTcpBinding,
          endpointAddress);

proxy = channelFactory.CreateChannel();

  • 如何防止客户端内存使用量持续增长?
  • 如果我只发送对象的通用列表而不是可序列化的字典,客户端上的内存使用量会大大降低吗?
  • 我是否已为这种实现方式正确设置了绑定配置?
  • 对于解决此内存问题的任何其他建议,将不胜感激.

推荐答案

•如何防止 客户端接口的增长 就记忆而言呈指数增长 用法?

•How can I prevent the client-interface from just growing exponentially in terms of memory usage?

Erm,它的增长不是指数级的,但是请确保您没有误用的引用, 尤其要查找可能引用了您的流浪对象的事件和lambda

Erm, its not growing exponentially, but make sure you dont have stray references, in particular look for events and lambda's that may have references to your stray objects

•请问 如果我发送,客户端要低很多 仅对象的通用列表为 反对可序列化的字典?

•Would the memory usage on the client-side be much lower if I sent only Generic Lists of objects as opposed to serializable dictionaries?

我对此表示怀疑.

•我是否已设置绑定 正确配置这种类型 实施?

•Have I setup my binding configurations correctly for this kind of implementation?

看不到任何明显的问题

•有关解决此问题的其他建议 内存问题会很大 赞赏.

•Any other suggestions for fixing this memory problem would be greatly appreciated.

查找Windbg,需要花费一些时间来正确学习,但是可以帮助您查看引用了什么的内容……可能不是您所期望的

Look up Windbg, it requires time to learn properly, but it can help you see what has references to what... it may not be what you expect

这篇关于C#WCF-客户端/服务器-System.OutOfMemory异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆