2010-10-12 85 views
3

我正在使用此WCF-WPF应用程序。我经常在异步XamDataGrid上收到此错误。尝试进行WCF调用并填充网格。我最初认为这与从WCF返回的大量数据有关,我通过仅为一个类别调用,使得调用返回数据非常小。这个错误随机出现,并不总是在同一组数据上。在15-20次尝试中足够可复制。WPF WCF MVVM OutOfMemoryException

我正在运行Windows XP(32位),双核,内存为4GB。当发生这种异常时,客户端机器仅使用大约2GB的RAM,而在服务器上W3WP仅使用800MB(6GB,3个内核,服务器上的总内存使用量为〜2GB)。

这只发生在XP机器上。在Windows 7上不会出现此错误。

请指导我如何解决此问题。

在此先感谢

Event Viewer Logs this Message: 
Event Type: Error 
Event Source: .NET Runtime 2.0 Error Reporting 
Event Category: None 
Event ID: 5000 
Date:  10/13/2010 
Time:  10:50:07 AM 
User:  N/A 
Computer: COMP-DC7800 
Description: 
EventType clr20r3, P1 appname.exe, P2 2.0.0.21872, P3 4cb0a1b1, P4 mscorlib, P5 2.0.0.0, P6 492b834a, P7 35df, P8 45, P9 system.outofmemoryexception, P10 NIL. 

下面ID异常的详细信息:

System.OutOfMemoryException was unhandled 
Message="Exception of type 'System.OutOfMemoryException' was thrown." 
Source="mscorlib" 
StackTrace: 
    at System.IO.MemoryStream.set_Capacity(Int32 value) 
    at System.IO.MemoryStream.EnsureCapacity(Int32 value) 
    at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count) 
    at System.Xml.XmlMtomReader.MimePart.GetBuffer(Int32 maxBuffer, Int32& remaining) 
    at System.Xml.XmlMtomReader.Initialize(Stream stream, String contentType, XmlDictionaryReaderQuotas quotas, Int32 maxBufferSize) 
    at System.Xml.XmlMtomReader.SetInput(Stream stream, Encoding[] encodings, String contentType, XmlDictionaryReaderQuotas quotas, Int32 maxBufferSize, OnXmlDictionaryReaderClose onClose) 
    at System.Xml.XmlMtomReader.SetInput(Byte[] buffer, Int32 offset, Int32 count, Encoding[] encodings, String contentType, XmlDictionaryReaderQuotas quotas, Int32 maxBufferSize, OnXmlDictionaryReaderClose onClose) 
    at System.ServiceModel.Channels.MtomMessageEncoder.MtomBufferedMessageData.TakeXmlReader() 
    at System.ServiceModel.Channels.BufferedMessageData.DoTakeXmlReader() 
    at System.ServiceModel.Channels.BufferedMessageData.GetMessageReader() 
    at System.ServiceModel.Channels.MessageHeaders.GetBufferedMessageHeaderReaderAtHeaderContents(IBufferedMessageData bufferedMessageData) 
    at System.ServiceModel.Channels.MessageHeaders.GetBufferedMessageHeaderReader(IBufferedMessageData bufferedMessageData, Int32 bufferedMessageHeaderIndex) 
    at System.ServiceModel.Channels.MessageHeaders.GetReaderAtHeader(Int32 headerIndex) 
    at System.ServiceModel.Channels.WsrmMessageInfo.Get(MessageVersion messageVersion, ReliableMessagingVersion reliableMessagingVersion, IChannel channel, ISession session, Message message, Boolean csrOnly) 
    at System.ServiceModel.Channels.ReliableDuplexSessionChannel.HandleReceiveComplete(IAsyncResult result) 
    at System.ServiceModel.Channels.ReliableDuplexSessionChannel.OnReceiveCompletedStatic(IAsyncResult result) 
    at System.ServiceModel.Diagnostics.Utility.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result) 
    at System.ServiceModel.AsyncResult.Complete(Boolean completedSynchronously) 
    at System.ServiceModel.Channels.ReliableChannelBinder`1.InputAsyncResult`1.OnInputComplete(IAsyncResult result) 
    at System.ServiceModel.Channels.ReliableChannelBinder`1.InputAsyncResult`1.OnInputCompleteStatic(IAsyncResult result) 
    at System.ServiceModel.Diagnostics.Utility.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result) 
    at System.ServiceModel.AsyncResult.Complete(Boolean completedSynchronously) 
    at System.ServiceModel.Channels.InputQueue`1.AsyncQueueReader.Set(Item item) 
    at System.ServiceModel.Channels.InputQueue`1.Dispatch() 
    at System.ServiceModel.Channels.InputQueue`1.OnDispatchCallback(Object state) 
    at System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.WorkItem.Invoke2() 
    at System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.WorkItem.OnSecurityContextCallback(Object o) 
    at System.Security.SecurityContext.Run(SecurityContext securityContext, ContextCallback callback, Object state) 
    at System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.WorkItem.Invoke() 
    at System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.ProcessCallbacks() 
    at System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.CompletionCallback(Object state) 
    at System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped) 
    at System.ServiceModel.Diagnostics.Utility.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped) 
    at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP) 
+0

如果你看电脑属性,它实际上报告4GB?在使用2GB内存时,您的流程需要多少钱? – 2010-10-12 17:22:30

+0

是的..这是使用的总内存。该过程仅使用〜400MB – Bhuvan 2010-10-12 18:57:25

+0

您是否检查过应用程序是否存在内存泄漏? – decyclone 2010-12-14 06:50:56

回答

0

感觉放心找到答案,微软搞砸了所有...... :)。那责备几乎救了我的工作......这是故事.. WCF有64kb的默认消息大小。在MSDN上找不到这个原因..所以当我们需要将最大消息大小更改为我们想要的。问题是threshold for LOH是85000b。如果消息大小超过该值,则该对象将被放置在LOH中,分析器将显示对象已经收集到,但是当您在Sysinternals Process Explorer,Process properties窗口中看到LOH大小时,仍然会看到内存使用正在增加。在800MB左右,我们强大的沃森博士出现并开始使用这个应用程序。显然,这是.NET 2.0

问题在.NET 4.0中仍然存在,但微软发布了quickfix的已知问题WCF &。 Sysinternals Process Explorer是帮助诊断这个问题的工具。见屏幕截图

+0

以某种方式附加一个PNG图像不工作.. – Bhuvan 2011-01-06 18:38:31

0

您将无法利用了4 GB与32位操作系统的RAM。

http://chris.pirillo.com/32-bit-windows-and-4gb-of-ram/

如果你使用你的应用程序正在消耗越来越多的内存,你可能想看看你的内存管理。查看为非托管资源的类实现IDisposable接口。另外,请避免在完成使用后保留对象的引用。事件对此尤其不利。

How do events cause memory leaks in C# and how do Weak References help mitigate that?

你也可以看看串流到一个临时文件,而不是流于记忆。

+1

@谢谢邪恶的鸽子{感到很不舒服,感谢一个邪恶的鸽子..犯罪的大多数宗教: )..你应该重新命名为天使鸽子} ..我检查了由于绑定,引用和“失败的WPF绑定”使用VS2010 Profiler(它真棒)的泄漏..它是非常小..在2MB以下..我我不知道这是否导致崩溃..我在邪恶的沃森博士出现之前看到的穗是600MB ..应该有其他东西.. – Bhuvan 2010-12-15 14:21:16

1

OutOfMemory异常可能会出现在很多原因中,特别是在Web应用程序中。

首先,如果你正在运行在IIS上,有具体到IIS设置来限制内存,在这里看到:http://blogs.msdn.com/b/pfedev/archive/2009/01/22/memory-based-recycling-in-iis-6-0.aspx

根据您的配置,游泳池等,这些限制可能不适用于.NET web应用程序。现在

,在ASP.NET中,也有一个设置的memoryLimitmachine.config中文件,指定允许的最大内存大小,系统内存总量的百分比,工作进程可以消耗之前ASP.NET启动一个新进程并重新分配现有的请求。

默认值是60%,相当于2G机器上的1.2G。

然而,...无论您配置,800M是一个32位的机器上ASP.NET应用程序的实际限制,在这里看到了很好的解释:Understanding ASP.Net memory

避免这个问题的解决办法是改变方式您的系统工作并且在更小的片断。

这就是为什么默认情况下,WCF已经被认真配置了很多限制(请参阅这里的广泛列表:http://weblogs.asp.net/paolopia/archive/2008/03/23/wcf-configuration-default-limits-concurrency-and-scalability.aspx)......几乎每个开发人员一旦发现它就会改变和最大化: )

+0

。问题在于WCF客户端。服务可以正常运行几个星期没有任何问题..内存使用固定在一个千兆..可能是因为我主持静态引用的客户端会话的双工通信。但这不是现在的问题..该应用程序是WCF-WPF-MVVM的Windows客户端。 – Bhuvan 2010-12-15 14:14:25

+1

客户端或服务器,出于与解释相同的原因,32位XP机器上的.NET进程的实际限制大约为800M。另一个链接:http://stackoverflow.com/questions/934314/maximum-memory-a-net-process-can-allocate。 WPF/MVVM可能与您的问题无关。您需要更改构建WCF服务接口的方式。 – 2010-12-15 17:18:17