WPF应用程序在Win7 x64上部署时内存不足
问题描述:
有谁知道什么会导致WPF应用程序出现以下异常?在Windows 7 x64上部署后开始发生。应用程序正在使用.NET 3.5,并且没有导致这种情况的具体操作,并且应用程序运行的时间长度是随机的。WPF应用程序在Win7 x64上部署时内存不足
Message : Insufficient memory to continue the execution of the program.
Source : PresentationCore
Help link :
Data : System.Collections.ListDictionaryInternal
TargetSite : Boolean CreateOrAddRefOnChannel(ResourceHandle ByRef, ResourceType)
Stack Trace : at System.Windows.Media.Composition.DUCE.Channel.CreateOrAddRefOnChannel(ResourceHandle& handle, ResourceType resourceType)
at System.Windows.Media.Composition.DUCE.MultiChannelResource.CreateOrAddRefOnChannel(Channel channel, ResourceType type)
at System.Windows.Media.RenderData.System.Windows.Media.Composition.DUCE.IResource.AddRefOnChannel(Channel channel)
at System.Windows.UIElement.RenderContent(RenderContext ctx, Boolean isOnChannel)
at System.Windows.Media.Visual.UpdateContent(RenderContext ctx, VisualProxyFlags flags, Boolean isOnChannel)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.UpdateChildren(RenderContext ctx, ResourceHandle handle)
at System.Windows.Media.Visual.RenderRecursive(RenderContext ctx)
at System.Windows.Media.Visual.Render(RenderContext ctx, UInt32 childIndex)
at System.Windows.Media.CompositionTarget.Compile(Channel channel)
at System.Windows.Media.CompositionTarget.System.Windows.Media.ICompositionTarget.Render(Boolean inResize, Channel channel)
at System.Windows.Media.MediaContext.Render(ICompositionTarget resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
答
我发现至少有一个这个问题的原因。如果DataGrid放置在容器中,如StackPanel允许子控件无限调整大小,那么当绑定大型列表(对于我17k行)时,会出现OutOfMemoryException。
如果您将DataGrid放置在一个固定高度的容器(如Grid)中,那么它工作正常。讽刺的是,我通过试用DevExpress WPF库发现了这一点。在这种情况下,它们的网格实际上会抛出一个异常,并带有以下文本
型“DevExpress.Xpf.Grid.InfiniteGridSizeException”的第一次机会异常出现在DevExpress.Xpf.Grid.v13.2.Core.dll 附加信息:默认情况下,无限电网高度是不允许的,因为所有网格行将被渲染,因此网格将工作得非常缓慢。要解决这个问题,你应该把网格放到一个容器中,这个容器将给网格一个有限的高度,或者你应该手动指定网格的Height或MaxHeight。请注意,您还可以通过将GridControl.AllowInfiniteGridSize静态属性设置为True来避免此异常,但在这种情况下,网格将缓慢运行。
一旦我看到这一分钱下降,我可以复制,然后修复与Microsoft DataGrid的原始行为。
看起来像一个无限循环,恰好在发生堆栈溢出之前耗尽内存/资源。 – benPearce 2012-04-10 22:11:06
错误是由本机代码Milcore生成的,它是DirectX的包装器。它是一个非常通用的错误代码,E_OUTOFMEMORY,它倾向于被本机代码用于多种原因。你的程序正在使用什么资源,它用完了。这一切都很清楚。 – 2012-04-11 00:01:47
@Hans,是的,它显然是应用程序用完了资源。在32位版本的Windows上运行时,此相同的应用程序永远不会耗尽资源。这是一个复杂的应用程序,它利用了大量的资源,所以我猜测通过编译迫使它在WOW64下以32位进程运行会引入一些这些问题。尤其是考虑到WOW64带来的内存和性能开销。我正在使用任何CPU编译应用程序以查看它的执行情况。我怀疑我们不会看到这些问题。 – 2012-04-15 18:42:35