Reputation: 17905
I've been dealing with this for long time. Sometime it throws invalid operation exception, sometimes out of memory. Random users, can run for days and crash multiple times within one day.
I got call stack from one user and can't understand what might be causing this. It's an WPF application with rich UI. Many views, lists. Using PRISM and regions.
It also uses background threads to listen on TCP, refresh data and sends PRISM notification on UI thread to update. Does this stack gives any clues on what I might need to check? It's not originating in my code..
at 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[[System.Windows.Freezable+FreezableContextPair, WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]].set_Capacity(Int32) at MS.Utility.FrugalObjectList`1[[System.Windows.Freezable+FreezableContextPair, WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]].Insert(Int32, FreezableContextPair) at System.Windows.Freezable.AddContextToList(System.Windows.DependencyObject, System.Windows.DependencyProperty) at System.Windows.Freezable.AddContextInformation(System.Windows.DependencyObject, System.Windows.DependencyProperty) at System.Windows.Freezable.AddInheritanceContext(System.Windows.DependencyObject, System.Windows.DependencyProperty) at System.Windows.DependencyObject.ProvideSelfAsInheritanceContext(System.Windows.DependencyObject, System.Windows.DependencyProperty) at System.Windows.Freezable.OnFreezablePropertyChanged(System.Windows.DependencyObject, System.Windows.DependencyObject, System.Windows.DependencyProperty)
at System.Windows.Media.RenderData.PropagateChangedHandler(System.EventHandler, Boolean) at System.Windows.UIElement.RenderClose(System.Windows.Media.IDrawingContent) at System.Windows.Media.VisualDrawingContext.CloseCore(System.Windows.Media.RenderData) at System.Windows.Media.RenderDataDrawingContext.DisposeCore() at System.Windows.Media.DrawingContext.System.IDisposable.Dispose() at System.Windows.Media.RenderDataDrawingContext.Close() at System.Windows.UIElement.Arrange(System.Windows.Rect) at System.Windows.Controls.DataGridCellsPanel.ArrangeChild(System.Windows.UIElement, Int32, ArrangeState) at System.Windows.Controls.DataGridCellsPanel.ArrangeOverride(System.Windows.Size) at System.Windows.FrameworkElement.ArrangeCore(System.Windows.Rect)
at System.Windows.UIElement.Arrange(System.Windows.Rect) at MS.Internal.Helper.ArrangeElementWithSingleChild(System.Windows.UIElement, System.Windows.Size) at System.Windows.Controls.ItemsPresenter.ArrangeOverride(System.Windows.Size) at System.Windows.FrameworkElement.ArrangeCore(System.Windows.Rect)
at System.Windows.UIElement.Arrange(System.Windows.Rect) at System.Windows.Controls.Control.ArrangeOverride(System.Windows.Size)
at System.Windows.Controls.Primitives.DataGridCellsPresenter.ArrangeOverride(System.Windows.Size) at System.Windows.FrameworkElement.ArrangeCore(System.Windows.Rect)
at System.Windows.UIElement.Arrange(System.Windows.Rect) at System.Windows.Controls.Grid.ArrangeOverride(System.Windows.Size)
at System.Windows.FrameworkElement.ArrangeCore(System.Windows.Rect)
at System.Windows.UIElement.Arrange(System.Windows.Rect) at System.Windows.Controls.Border.ArrangeOverride(System.Windows.Size)
at System.Windows.FrameworkElement.ArrangeCore(System.Windows.Rect)
at System.Windows.UIElement.Arrange(System.Windows.Rect) at System.Windows.Controls.Control.ArrangeOverride(System.Windows.Size)
at System.Windows.Controls.DataGridRow.ArrangeOverride(System.Windows.Size) at System.Windows.FrameworkElement.ArrangeCore(System.Windows.Rect)
at System.Windows.UIElement.Arrange(System.Windows.Rect) at System.Windows.Controls.VirtualizingStackPanel.ArrangeOtherItemsInExtendedViewport(Boolean, System.Windows.UIElement, System.Windows.Size, Double, Int32, System.Windows.Rect ByRef, System.Windows.Size ByRef, System.Windows.Point ByRef, Int32 ByRef) at System.Windows.Controls.VirtualizingStackPanel.ArrangeOverride(System.Windows.Size) at System.Windows.FrameworkElement.ArrangeCore(System.Windows.Rect)
at System.Windows.UIElement.Arrange(System.Windows.Rect) at System.Windows.ContextLayoutManager.UpdateLayout() at System.Windows.ContextLayoutManager.UpdateLayoutCallback(System.Object) at System.Windows.Media.MediaContext+InvokeOnRenderCallback.DoWork()
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(System.Object) at System.Windows.Media.MediaContext.RenderMessageHandler(System.Object) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate) at System.Windows.Threading.DispatcherOperation.InvokeImpl() at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object) at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) at System.Windows.Threading.DispatcherOperation.Invoke() at System.Windows.Threading.Dispatcher.ProcessQueue() at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef) at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate) at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef) at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame) at System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame) at System.Windows.Threading.Dispatcher.Run() at System.Windows.Application.RunDispatcher(System.Object) at System.Windows.Application.RunInternal(System.Windows.Window) at System.Windows.Application.Run(System.Windows.Window) at ArturExpress.Main.App.Main()
Upvotes: 0
Views: 1370
Reputation: 38367
There's a set_Capacity which usually causes an attempt to allocate a contiguous block of memory. If it is large enough it will be requested from the large object heap, which is not compacted, and thus fragmentation can make it difficult to find a contiguous block of memory to satisfy the request.
A memory profiler would be my next step, although if you are getting other types of exceptions then logging would be better.
For desktop apps I used log4net with an in memory logger with detailed info logs for last 500 messages. If an exception occurred I'd direct this to a file, this way I'd have a very detailed context of what was going on leading up to an exception.
Note adjusting capacity for some collections often requires 3 times the memory needed to grow the array. This is because when they exceed current capacity, they allocate a new array twice the size of the current, and copy existing items to the new array. So during this transition the collection requires 3 times the memory, the current array being copied from and the twice larger array being copied to. I don't know if that's what is happening here though. You usually see an increasing saw tooth pattern in the memory profile when you have arrays who's capacity is growing often.
Upvotes: 1
Reputation: 1236
What can be determined from this stacktrace is that the out of memory exception took place during a UpdateLayout of a StackPanel that contains, among other things, a DataGrid.
When one of the DataGrid rows was asked to re-arrange itself, one of the cells (which seems to contain a panel) that looks to be part of a frozen column ended up either going from Frozen to Unfrozen (or vice versa) at which time the out of memory exception occurred while trying to construct a FreezableContextPair object.
Whether this is coincidental or causation is impossible to say without additional datapoints. In other words, if 10 more stacktraces showed the exact same trace then it is probably a specific set of events having to do with one of your grids having a column going from freezable to unfreezable that for some reason causes the out of memory exception.
If other stacktraces show completely different outcomes then this particular exception is probably coincidental, e.g. something pushed the memory usage to the brink and this particular operation happened to be the one that pushed it over the edge.
You need more datapoints to determine and should ask your users to start sending stacktraces when this happens + run the app in a memory profiler to see if you can see any anomalies.
Upvotes: 1