OutOfMemoryException-从您的经验中得出的想法

问题描述 投票:0回答:1

我面临内存不足异常的问题,错误消息被App_DispatcherUnhandledException捕获(某些错误消息中的1条:]

Message: Zgłoszono wyjątek typu 'System.OutOfMemoryException'. Source: PresentationFramework 

StackTrace:   
 w System.Windows.TreeChangeInfo.CreateParentInheritableProperties(DependencyObject d, DependencyObject parent, Boolean isAddOperation)
   w System.Windows.TreeWalkHelper.InvalidateOnTreeChange(FrameworkElement fe, FrameworkContentElement fce, DependencyObject parent, Boolean isAddOperation)
   w System.Windows.FrameworkElement.OnVisualParentChanged(DependencyObject oldParent)
   w System.Windows.Media.Visual.FireOnVisualParentChanged(DependencyObject oldParent)
   w System.Windows.Media.Visual.AddVisualChild(Visual child)
   w System.Windows.FrameworkElement.set_TemplateChild(UIElement value)
   w System.Windows.FrameworkTemplate.WireRootObjectToParent(Object createdObject, DependencyObject rootObject, DependencyObject container, FrameworkElement feContainer, INameScope nameScope)
   w System.Windows.FrameworkTemplate.HandleBeforeProperties(Object createdObject, DependencyObject& rootObject, DependencyObject container, FrameworkElement feContainer, INameScope nameScope)
   w System.Windows.FrameworkTemplate.<>c__DisplayClass45_0.<LoadOptimizedTemplateContent>b__2(Object sender, XamlObjectEventArgs args)
   w System.Xaml.XamlObjectWriter.OnBeforeProperties(Object value)
   w System.Xaml.XamlObjectWriter.Logic_CreateAndAssignToParentStart(ObjectWriterContext ctx)
   w System.Xaml.XamlObjectWriter.WriteEndObject()
   w System.Xaml.XamlWriter.WriteNode(XamlReader reader)
   w System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)
   w System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlObjectWriter objectWriter)
   w System.Windows.FrameworkTemplate.LoadOptimizedTemplateContent(DependencyObject container, IComponentConnector componentConnector, IStyleConnector styleConnector, List`1 affectedChildren, UncommonField`1 templatedNonFeChildrenField)
   w System.Windows.FrameworkTemplate.LoadContent(DependencyObject container, List`1 affectedChildren)
   w System.Windows.StyleHelper.ApplyTemplateContent(UncommonField`1 dataField, DependencyObject container, FrameworkElementFactory templateRoot, Int32 lastChildIndex, HybridDictionary childIndexFromChildID, FrameworkTemplate frameworkTemplate)
   w System.Windows.FrameworkTemplate.ApplyTemplateContent(UncommonField`1 templateDataField, FrameworkElement container)
   w System.Windows.FrameworkElement.ApplyTemplate()
   w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   w System.Windows.UIElement.Measure(Size availableSize)
   w System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   w System.Windows.UIElement.Measure(Size availableSize)
   w System.Windows.Controls.Control.MeasureOverride(Size constraint)
   w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   w System.Windows.UIElement.Measure(Size availableSize)
   w Telerik.Windows.Controls.GridView.GridViewCellsPanel.MeasureCell(IColumnElement column, GridViewCellBase cell, Size size)
   w Telerik.Windows.Controls.GridView.GridViewCellsPanel.RealizeAndMeasureCells(Int32 startIndex, Int32 predictedLastIndex, Func`2 calculateLastIndex)
   w Telerik.Windows.Controls.GridView.GridViewCellsPanel.UpdateVirtualizedCells()
   w Telerik.Windows.Controls.GridView.GridViewCellsPanel.MeasureOverride(Size availableSize)
   w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   w System.Windows.UIElement.Measure(Size availableSize)
   w MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
   w System.Windows.Controls.ItemsPresenter.MeasureOverride(Size constraint)
   w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   w System.Windows.UIElement.Measure(Size availableSize)
   w System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   w System.Windows.UIElement.Measure(Size availableSize)
   w System.Windows.Controls.Control.MeasureOverride(Size constraint)
   w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   w System.Windows.UIElement.Measure(Size availableSize)
   w System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
   w System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
   w System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   w System.Windows.UIElement.Measure(Size availableSize)
   w System.Windows.Controls.Border.MeasureOverride(Size constraint)
   w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   w System.Windows.UIElement.Measure(Size availableSize)
   w System.Windows.Controls.Control.MeasureOverride(Size constraint)
   w Telerik.Windows.Controls.GridView.GridViewRowItem.MeasureOverride(Size availableSize)
   w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   w System.Windows.UIElement.Measure(Size availableSize)
   w Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.FlatLayoutStrategy.RealizeRows(Int32 startIndex, Int32 endIndex, Double& verticalOffset, HashSet`1& realizedRows)
   w Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.FlatLayoutStrategy.MeasureOverride(Size availableSize)
   w Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.MeasureOverride(Size availableSize)
   w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   w System.Windows.UIElement.Measure(Size availableSize)
   w MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
   w System.Windows.Controls.ScrollContentPresenter.MeasureOverride(Size constraint)
   w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   w System.Windows.UIElement.Measure(Size availableSize)
   w System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
   w System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
   w System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
   w System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   w System.Windows.UIElement.Measure(Size availableSize)
   w System.Windows.Controls.ScrollViewer.MeasureOverride(Size constraint)
   w Telerik.Windows.Controls.GridView.GridViewScrollViewer.MeasureOverride(Size availableSize)
   w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   w System.Windows.UIElement.Measure(Size availableSize)
   w System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
   w System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
   w System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
   w System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   w System.Windows.UIElement.Measure(Size availableSize)
   w System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   w System.Windows.UIElement.Measure(Size availableSize)
   w System.Windows.Controls.Control.MeasureOverride(Size constraint)
   w Telerik.Windows.Controls.GridView.GridViewDataControl.MeasureOverride(Size availableSize)
   w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   w System.Windows.UIElement.Measure(Size availableSize)
   w System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   w System.Windows.UIElement.Measure(Size availableSize)
   w System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
   w System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
   w System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
   w System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   w System.Windows.UIElement.Measure(Size availableSize)
   w System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
   w System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
   w System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
   w System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   w System.Windows.UIElement.Measure(Size availableSize)
   w MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
   w System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
   w System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   w System.Windows.UIElement.Measure(Size availableSize)
   w System.Windows.ContextLayoutManager.UpdateLayout()
   w System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
   w System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
   w System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
   w System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
   w System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
   w System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   w System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

HResult: -2147024882

以下是一些信息:

  • 应用程序在RDS上运行,有15-25个用户使用该应用程序

  • 可用内存:32 GB

  • 平均已使用内存:17 GB

  • 永远不会出现这种情况,即已用内存达到30 GB(最高峰值约为23 GB)

  • CPU很好,平均40%,使用的峰值为60%

  • 每个应用程序实例的RAM使用量随每个实例的使用量增加到约1.5 GB。

  • 根据VS Profiler和其他探查器(包括JetBrains之一),对应用程序进行了多次剖析,内存泄漏为0,

  • [App使用Telerik库

  • [App使用实体框架

我有点困惑,不知道在哪里寻找潜在问题。优化花费了我数周的时间,而且进展顺利-我设法解决了典型的内存泄漏和内存分配问题,有时应用程序需要手动启动GC.Collect(),但这种情况很少发生。当OutOfMemoryException命中时,也没有任何模式,使我不知道在哪里寻找问题。因此,我正在寻找经验丰富的WPF开发人员,以便与我分享有关此类问题的经验。

最后一件事情:

我认为应用程序对于WPF来说太大了,这是由于经典WPF内存的增长(在几个小时的时间内应用程序的内存使用量从60K上升到1.5k),但是除了解决这个问题,我别无选择。

有什么想法吗?

wpf out-of-memory
1个回答
0
投票

很难找出这样的确切原因,但我可以建议一些故障排除机制。

  1. 您的堆栈跟踪建议您使用的是telerik gridview。尝试将其注释掉或替换为普通的gridview,看看是否仍然有异常。这样,至少您可以确定哪个元素是罪魁祸首。确认引起问题的元素后,请尝试通过继承同一类型来创建自定义控件。然后在所有方法中添加日志,调用基本方法。这样,您将不会同时失去功能,可以确认问题所在。

  2. 检查您是否遇到某种无限循环。调用堆栈建议,当尝试渲染所有元素时,它的内存不足。如果所涉及的某种ItemSource太大而使用循环依赖控件,则可能会发生这种情况。

© www.soinside.com 2019 - 2024. All rights reserved.