【发布时间】:2011-03-19 09:42:32
【问题描述】:
我在一个应用程序中有一个 UserControl,我不断地与其他 UIElements 交换 Content 属性。
但是我在任务管理器中注意到,经过多次交换后内存增加了。
使用 AntProfiler,我注意到 ToolBarAutomationPeer 引用了 UserControl。
为了修复此内存泄漏,我使用以下代码创建了自己的 UserControl
public class MyUserControl : UserControl
{
protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
{
return null;
}
}
这似乎删除了UserControl 可能引用的任何AutomationPeer 实例,这些实例可能会将我正在交换的内容保留在内存中...
但我仍然想知道ToolBarAutomationPeer 是如何进入我的UserControl 的,以及我在OnCreateAutomationPeer 方法中返回null 的后果是什么?
我不熟悉自动化调用,不确定它们何时有用。
【问题讨论】:
标签: wpf memory user-controls memory-leaks