私のアプリケーションは、すべてのUIコントロールにバインドされたBindinglistから継承するカスタムリストを使用します。このリストは、INotifyPropertyChangedを実装する基本オブジェクトの集合です。私はメモリリークの疑いがあり、 memprofilerを使用してアプリケーションをプロファイリングしました。私のリストは決して廃棄されず、バインディングリストのpropertyChangedイベントハンドラに登録されているために固執しています。ここでBindingListメモリリーク
私のオブジェクトのサンプル
public abstract class BaseObject:IDataErrorInfo,INotifyPropertyChanged,ICloneable
{
private Guid _Id = Guid.NewGuid();
public virtual Guid ID
{
get { return this._Id; }
set { this._Id = value; this.OnPropertyChange(new
PropertyChangedEventArgs(propertyName)); }
}
[field:NonSerialized]
public virtual event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChange(PropertyChangedEventArgs e)
{
if (this.PropertyChanged != null) this.PropertyChanged(this, e);
}
}
[Serializable]
public class BaseList<T> :BindingList<T>,ICloneable where T:BaseObject
{
public new void Add(T item)
{
<Custom code>
base.Add(item);
}
public new void Remove(T item)
{
<Custom Code>
base.Remove(item);
}
}
ここでは、プロファイラ
[Skipped frame(s)]
mscorlib!System.MulticastDelegate.CombineImpl(Delegate)
mscorlib!System.Delegate.Combine(Delegate, Delegate)
<AppName>.Data!<AppName>.Data.BaseObject.add_PropertyChanged(
PropertyChangedEventHandler)
[Skipped frame(s)]
System!System.ComponentModel.BindingList<T>.InsertItem(int, T)
mscorlib!System.Collections.ObjectModel.Collection<T>.Add(T)
<AppName>.Data.BaseList<T>.Add(T) BaseList.cs
<AppName>.UI.Forms.Form1.GetData() Form1
<AppName>.UI.Forms.Form1.Initialize() Form1
<AppName>.UI.Forms.Form1.RunAsyncComplete() Form1
から割り当てスタックは、誰かが配置されたリストを得ることに私を助けることができるです。
おかげで、すべての
ヘンクは、あなたは正しかったです。問題は私が言及したコードではなく、代わりに私のフォームが処分されるのを妨げている代理人に絞った。私はサイトにアップロードする問題を再現するためのサンプルを作成しています。ありがとう