什么样的事情可能导致OutOfMemoryException?

问题描述 投票:-1回答:2

我面临内存不足异常的问题,错误消息被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内存的增长(在几个小时的时间内应用程序的内存使用量从60K上升到1.5k),但是我别无选择,只能解决这个问题问题。

编辑

我不是RDS环境的管理员,有另一位工程师进行部署和管理,也许他可能进行了某种更改,开始引起此问题?

wpf telerik out-of-memory
2个回答
0
投票

“内存泄漏为0”是一个很强的说法。内存泄漏通常会在非常特定的情况下显示出来,因此您应该分析每个可能的工作流程以说明这一点-这对于大型应用程序是不切实际/不可能的。因此,您所能做的最好的事情可能是采访用户有关他们的使用模式,并尝试使用附加的探查器在本地重现泄漏。

此外,调查OutOfMemoryException的调用堆栈并不总是有用,因为如果没有足够的内存,any分配可能会导致它(因此,也许可以怪Telerik,尽管您可以检查他们的反馈门户对于提及memoryOutOfMemoryException的公共问题。

否则,正如注释中的suggested,大多数好的分析器会检测到常见的内存泄漏,甚至是常见的WPF内存泄漏,但是,再次,您必须运行应用程序通过特定场景(例如,打开并关闭特定窗口),拍摄快照并调查分析器建议。

最后,默认情况下,WPF应用程序作为x86进程运行,实际上为它们提供了大约2GB的最大内存。当然,有些类的应用程序只需要更多的内存(例如,处理内存中的大量文本流),如果是这种情况,则可以尝试将应用程序切换到x64进程,这将允许更多的内存(16TB?记住)记忆。请记住,这可能会进一步增加您的内存(作为现在的简单类型use twice more memory),并有可能减慢您的应用程序的速度。运行带有调试器的x64应用程序也具有some caveats


0
投票

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

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

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

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