簡體   English   中英

WPF應用程序因OOM異常隨機崩潰

[英]WPF Application crashes randomly with OOM exception

我已經處理了很長時間了。 有時會引發無效的操作異常,有時會耗盡內存。 隨機用戶可以運行幾天,一天之內會崩潰多次。

我從一個用戶那里收到了調用堆棧,無法理解是什么原因造成的。 這是具有豐富UI的WPF應用程序。 許多視圖,列表。 使用棱鏡和區域。

它還使用后台線程偵聽TCP,刷新數據並在UI線程上發送PRISM通知以進行更新。 這個堆棧是否提供有關我可能需要檢查的任何線索? 它不是源於我的代碼。

在MS.Utility.ArrayItemList 1[[System.Windows.Freezable+FreezableContextPair, WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]..ctor(Int32) at MS.Utility.FrugalObjectList 1 [[系統.Windows.Freezable + FreezableContextPair,WindowsBase,版本= 4.0.0.0,文化=中性,PublicKeyToken = 31bf3856ad364e35]]。set_Capacity(Int32)at MS.Utility.FrugalObjectList`1 [[System.Windows.Freezable + FreezableContextPair,WindowsBase,版本= 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35]]。在System.Windows.Freezable.AddContextInformation上插入(Int32,FreezableContextPair)在System.Windows.Freezable.AddContextToList(System.Windows.DependencyObject,System.Windows.DependencyProperty) System.Windows.Freezable.AddInheritanceContext(System.Windows.DependencyObject,System.Windows.DependencyProperty)(System.Windows.DependencyObject.ProvideSelfAsInheritanceContext(System.Windows.DependencyObject, System.Windows.Freezable.OnFreezablePropertyChanged(System.Windows.DependencyObject,System.Windows.DependencyObject,System.Windows.DependencyProperty)上的System.Windows.DependencyProperty)
在System.Windows.Media.VisualDrawingContext.CloseCore(System.Windows.Media.RenderData.PropagateChangedHandler(System.EventHandler,Boolean)在System.Windows.UIElement.RenderClose(System.Windows.Media.IDrawingContent) System.Windows.Media.RenderDataDrawingContext.DisposeCore()的System.Windows.Media.RenderDataDrawingContext.DisposeCore()的System.Windows.Media.RenderDataDrawingContext.Close()的System.Windows.UIElement處的.RenderData)。在System.Windows的System.Windows.Controls.DataGridCellsPanel.ArrangeChild(System.Windows.UIElement,Int32,ArrangeState)的Arrange(System.Windows.Rect)在System.Windows的System.Windows.Controls.DataGridCellsPanel.ArrangeOverride(System.Windows.Size) .FrameworkElement.ArrangeCore(System.Windows.Rect)
MS.Internal.Helper.ArrangeElementWithSingleChild(System.Windows.UIElement,System.Windows.Size)的System.Windows.UIElement.Arrange(System.Windows.Rect)的System.Windows.Controls.ItemsPresenter.ArrangeOverride(System.Windows) .Size)位於System.Windows.FrameworkElement.ArrangeCore(System.Windows.Rect)
在System.Windows.Controls.Control.ArrangeOverride(System.Windows.Size)處System.Windows.UIElement.Arrange(System.Windows.Rect)
在System.Windows.FrameworkElement.ArrangeCore(System.Windows.Rect)處System.Windows.Controls.Primitives.DataGridCellsPresenter.ArrangeOverride(System.Windows.Size)
在System.Windows.Controls.Grid.ArrangeOverride(System.Windows.Size)處System.Windows.UIElement.Arrange(System.Windows.Rect)
在System.Windows.FrameworkElement.ArrangeCore(System.Windows.Rect)
在System.Windows.Controls.Border.ArrangeOverride(System.Windows.Size)處System.Windows.UIElement.Arrange(System.Windows.Rect)
在System.Windows.FrameworkElement.ArrangeCore(System.Windows.Rect)
在System.Windows.Controls.Control.ArrangeOverride(System.Windows.Size)處System.Windows.UIElement.Arrange(System.Windows.Rect)
在System.Windows.FrameworkElement.ArrangeCore(System.Windows.Rect)處的System.Windows.Controls.DataGridRow.ArrangeOverride(System.Windows.Size)
在System.Windows.Controls.VirtualizingStackPanel.ArrangeOtherItemsInExtendedViewport(System.Windows.UIElement.Arrange(System.Windows.Rect)處)(Boolean,System.Windows.UIElement,System.Windows.Size,Double,Int32,System.Windows.Rect ByRef ,System.Windows.Controls.VirtualizingStackPanel.ArrangeOverride(System.Windows.Size),System.Windows.FrameworkElement.ArrangeCore(System.Windows.Rect)處的System.Windows.Size ByRef,System.Windows.Point ByRef,Int32 ByRef)
在System.Windows.UI.UIElement.Arrange(System.Windows.Rect)在System.Windows.ContextLayoutManager.UpdateLayout()在System.Windows.ContextLayoutManager.UpdateLayoutCallback(System.Object)在System.Windows.Media.MediaContext + InvokeOnRenderCallback.DoWork ()
在System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
在System.Windows.Media.MediaContext.RenderMessageHandlerCore(System.Object)在System.Windows.Media.MediaContext.RenderMessageHandlerCore(System.Object)在System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate,System.Object,Int32 )在MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object,System.Delegate,System.Object,Int32,System.Delegate)在System.Windows.Threading.DispatcherOperation.InvokeImpl()在System.Windows.Threading.DispatcherOperation System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object,Boolean)處的System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,System.InvokeInSecurityContext(System.Object) System.Windows.Threading.DispatcherOperation.Invoke()處的System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object)處的.Threading.ContextCallback,System.Object,Boolean) .wi MS.Win32.HwndWrapper.WndProc(IntPtr,Int32,IntPtr,IntPtr,System.Windows.Threading.Dispatcher.WndProcHook(IntPtr,Int32,IntPtr,IntPtr,Boolean ByRef)處的ndows.Threading.Dispatcher.ProcessQueue() ),位於MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object),位於System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate,System.Object,Int32),位於MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, MS的System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority,System.TimeSpan,System.Delegate,System.Object,Int32)中的System.Delegate,System.Object,Int32,System.Delegate)。 Win32.HwndSubclass.SubclassWndProc(IntPtr,Int32,IntPtr,IntPtr)
在System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)在MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)在System.Windows.Threading.Dispatcher.PushFrame(System。 Windows上的System.Windows.Application.RunDispatcher(System.Object)的System.Windows.Application.RunDispatcher(System.Object)的System.Windows.Application.RunInternal(System.Windows.Window)的Windows.Threading.Dispatcher.Run() ArturExpress.Main.App.Main()上的.Application.Run(System.Windows.Window)

從此堆棧跟蹤可以確定的是,內存不足異常發生在包含(其中包括)DataGrid的StackPanel的UpdateLayout期間。

當要求其中一個DataGrid行重新排列自身時,看起來像是凍結列的一部分的單元格(似乎包含一個面板)最終從“凍結”變為“未凍結”(反之亦然)嘗試構造FreezableContextPair對象時發生內存不足異常。

沒有其他數據點就無法說這是巧合還是因果關系。 換句話說,如果另外10條堆棧跟蹤顯示了完全相同的跟蹤,則可能是一組特定事件與您的一個網格有關,該網格的列從可凍結變為不可凍結,由於某種原因會導致內存不足異常。

如果其他堆棧跟蹤顯示出完全不同的結果,則該特殊異常可能是偶然的,例如,某項操作將內存使用率推到了高潮,而該特定操作恰好是將其推到邊緣的操作。

您需要更多數據點來確定,並且應該要求您的用戶在發生這種情況時開始發送堆棧跟蹤記錄,然后在內存分析器中運行該應用程序以查看是否可以看到任何異常。

有一個set_Capacity通常會導致嘗試分配一個連續的內存塊。 如果足夠大,則會從大型對象堆中進行請求,而該對象堆不會進行壓縮,因此碎片化可能會導致很難找到連續的內存塊來滿足請求。

內存探查器將是我的下一步,盡管如果您遇到其他類型的異常,則記錄會更好。

對於台式機應用程序,我將log4net與內存記錄器一起使用,其中包含最近500條消息的詳細信息日志。 如果發生異常,我會將其定向到文件中,這樣,我將非常詳細地了解導致異常的原因。

請注意,為某些集合調整容量通常需要3倍於增長陣列所需的內存。 這是因為當它們超過當前容量時,它們會分配一個兩倍於當前容量的新陣列,並將現有項目復制到新陣列中。 因此,在此過渡期間,集合需要3倍的內存,要從中復制當前數組,並向其復制兩倍的較大數組。 我不知道這是否正在發生。 當陣列的容量經常增長時,通常會在內存配置文件中看到鋸齒狀模式的增加。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM