Reputation: 336
I am using PerfView in order to discover memory leaks.
After comparing between two snapshot I noticed that under the tab RefTree -> static vars in PerView.
MyPageDependencyProperty
of mine takes 78.9% of the Inc%.
The MyPageDependencyProperty
should not be there because I closed the the xaml window it is belong to.
I don't use AddValueChanged
which can cause memory leak.
The DependencyProperty
reveals ObservableCollection<object>
.
Does anyone know can I solve this issue?
thanks
Upvotes: 4
Views: 3242
Reputation: 8801
Instead of defining your property like this which creates a static ObservableCollection.
public static readonly DependencyProperty SomePropertyProperty = DependencyProperty.Register(typeof(..), typeof(..),....,.... , new ObservableCollection<...>());
You should do this:
public static readonly DependencyProperty SomePropertyProperty = DependencyProperty.Register(typeof(..), typeof(..),...., null);
public MyControl()
{
this.SomeProperty = new ObservableCollection<...>();
}
And your issue will disappear magically. :)
Upvotes: 5
Reputation:
This may be because of CLR has the links to the object somewhere and it doesn't Dispose
. Try to force Garbage collector to run and track what will happen.
Upvotes: -3