【问题标题】:VSTO 4.0 Excel 2007 Add-in causing Memory leaks on Windows 7VSTO 4.0 Excel 2007 加载项导致 Windows 7 上的内存泄漏
【发布时间】:2011-04-15 03:46:09
【问题描述】:

我们有一个用于 Excel 2007 的 VSTO 4.0 加载项,它似乎存在内存泄漏问题,但仅限于某些文档且仅在 Windows 7 上。该行为类似于据称在 VSTO 4 中得到解决的 LCID 代理问题。内存峰值大约为 1.2 到 1.5 GB,然后引发 OutOfMemory 异常。这似乎只发生在我尝试在 Windows 7 上运行时打开某些文档时。如果我在 XP 中打开相同的文档,内存肯定会变高,但我没有遇到异常。基本上,我得到了各种例外,而且从来没有在同一个地方两次:

----- 来源:System.Windows.Forms -----

System.OutOfMemoryException:引发了“System.OutOfMemoryException”类型的异常。

在 System.Windows.Forms.Screen.FromRectangle(Rectangle rect)

在 System.Windows.Forms.Screen.GetWorkingArea(Rectangle rect)

在 System.Windows.Forms.WindowsFormsUtils.ConstrainToScreenWorkingAreaBounds(矩形边界)

在 System.Windows.Forms.ToolStripDropDown.GetDropDownBounds(RectangleSuggestedBounds)

在 System.Windows.Forms.ToolStripDropDown.SetBoundsCore(Int32 x, Int32 y, Int32 width, Int32 height, BoundsSpecified 指定)

在 System.Windows.Forms.Control.SetBounds(Int32 x, Int32 y, Int32 width, Int32 height, BoundsSpecified specified)

在 System.Windows.Forms.Control.set_Size(大小值)

在 System.Windows.Forms.ToolStripDropDown.AdjustSize()

在 System.Windows.Forms.ToolStripDropDown.OnLayout(LayoutEventArgs e)

在 System.Windows.Forms.ToolStripDropDownMenu.OnLayout(LayoutEventArgs e)

在 System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)

在 System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.PerformLayout(IArrangedElement 影响元素,字符串影响属性)

在 System.Windows.Forms.Layout.LayoutTransaction.DoLayout(IArrangedElement elementToLayout, IArrangedElement elementCausingLayout, String 属性)

在 System.Windows.Forms.ToolStripItem.InvalidateItemLayout(字符串影响属性,布尔 invalidatePainting)

在 System.Windows.Forms.ToolStripItem.InvalidateItemLayout(字符串影响属性)

在 System.Windows.Forms.ToolStripItem.OnRightToLeftChanged(EventArgs e)

在 System.Windows.Forms.ToolStripDropDownItem.OnRightToLeftChanged(EventArgs e)

在 System.Windows.Forms.ToolStripItem.OnOwnerChanged(EventArgs e)

在 System.Windows.Forms.ToolStripMenuItem.OnOwnerChanged(EventArgs e)

在 System.Windows.Forms.ToolStripItem.SetOwner(ToolStrip newOwner)

在 System.Windows.Forms.ToolStripItemCollection.SetOwner(ToolStripItem 项)

在 System.Windows.Forms.ToolStripItemCollection.Add(ToolStripItem 值)

在 C:\Serenity6.x\Source\Hcg\Stinger\Report\ShadowRangeTree\ShadowRangeNodeEventBehavior.cs:第 135 行中的 Hcg.Stinger.Report.ShadowRangeTree.ShadowRangeNodeEventBehavior.AddDynamicLabelMenu() 处

这是另一个:

----- 来源:System.Windows.Forms -----

System.OutOfMemoryException:引发了“System.OutOfMemoryException”类型的异常。

在 System.Windows.Forms.ToolStripManager.ProcessShortcut(Message& m, Keys shortcut)

在 System.Windows.Forms.ToolStripManager.ProcessCmdKey(Message& m, Keys keyData)

在 System.Windows.Forms.ContainerControl.ProcessCmdKey(Message& msg, Keys keyData)

在 System.Windows.Forms.Form.ProcessCmdKey(Message& msg, Keys keyData)

在 System.Windows.Forms.Control.ProcessCmdKey(Message& msg, Keys keyData)

在 System.Windows.Forms.Control.ProcessCmdKey(Message& msg, Keys keyData)

在 System.Windows.Forms.TextBoxBase.ProcessCmdKey(Message& msg, Keys keyData)

在 System.Windows.Forms.Control.PreProcessMessage(Message& msg)

在 System.Windows.Forms.Control.PreProcessControlMessageInternal(Control target, Message& msg)

在 System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg)


当我将文档保存为独立文档并且不使用 VSTO 插件打开它们时,它能够以最少的内存打开它们。当我使用插件打开它们时,就会出现问题并崩溃。

任何有关 Windows 7 为何存在这些问题的帮助或指示将不胜感激。

谢谢,

埃里克

【问题讨论】:

    标签: vsto excel-2007


    【解决方案1】:

    实际上,我发现应用程序正在为 TreeNode 上的上下文菜单创建数千个 ToolStripMenuItem。一旦我分享了这些内容,它就解决了内存问题。

    【讨论】:

    • 你所说的“一旦我让那些共享......”是什么意思???我还有内存问题和包含各种 ToolStripMenuItems 的 ContextMenuStrip-Controls。但我不知道如何让它们“共享”。你能帮忙吗?
    • @jreichert 我所说的共享是简单地将它们添加到树菜单上下文中。我一直在为每个节点创建单独的节点。我只是使用规则来决定哪个节点显示哪些规则。
    猜你喜欢
    • 1970-01-01
    • 2016-10-26
    • 1970-01-01
    • 1970-01-01
    • 2019-06-11
    • 1970-01-01
    • 1970-01-01
    • 2011-01-23
    • 2023-04-09
    相关资源
    最近更新 更多