views:

55

answers:

1

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.

+1  A: 

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!

Jeff Wilcox