简体   繁体   English

使用WPF和ItemsControl(VB.NET)的内存泄漏

[英]Memory leak with WPF & ItemsControl (VB.NET)

I have an ItemsControl that uses a DataTemplate to display properties in my customClass that implements INotifyPropertyChanged... 我有一个ItemsControl,它使用DataTemplate在实现INotifyPropertyChanged的customClass中显示属性。

Pretty straightforward... 很简单...

Some items in the DataTemplate use CommandBindings (such as buttons), and a few have some code-behind (yuck). DataTemplate中的某些项目使用CommandBindings(例如按钮),而另一些则具有一些代码隐藏(糟糕)。

When I empty the ItemsControl and set all instances of customClass = Nothing , no memory is released from my program. 当我清空ItemsControl并设置customClass = Nothing所有实例时,程序不会释放任何内存。 This becomes a problem pretty quickly! 这很快就成为问题!

Any idea where I should start looking? 知道我应该从哪里开始寻找? I've even gone so far as to completely traverse the visual tree of each DataTemplate instance and set each Visual = Nothing. 我什至可以完全遍历每个DataTemplate实例的可视树并设置每个Visual = Nothing. I'm not really if that's supposed to have any effect though. 我不是真的应该有什么作用。

Not completely sure where all to look, but definitely check to see if there are underlying event connections being made. 不能完全确定所有内容在哪里,但可以肯定地检查是否建立了基础事件连接。

If an event delegate add operation is present, make sure to remove it. 如果存在事件委托添加操作,请确保将其删除。

If the Command bindings look to be the issue, consider finding a way to clear the Command binding when setting to nothing. 如果命令绑定看起来是问题所在,请设置为空时考虑寻找一种方法来清除命令绑定。

Also, more drastic, start looking to use WeakReferences, etc., until you can at least pinpoint what is causing the leak(s). 另外,更加剧烈地开始使用WeakReferences等,直到您至少可以查明导致泄漏的原因。

Happy hunting! 狩猎愉快!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM