简体   繁体   中英

Memory leak with WPF & ItemsControl (VB.NET)

I have an ItemsControl that uses a DataTemplate to display properties in my customClass that implements INotifyPropertyChanged...

Pretty straightforward...

Some items in the DataTemplate use CommandBindings (such as buttons), and a few have some code-behind (yuck).

When I empty the ItemsControl and set all instances of customClass = Nothing , no memory is released from my program. 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. 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).

Happy hunting!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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