我的应用程序使用自定义列表,该列表继承自Bindinglist,然后绑定到所有UI控件。列表是实现INotifyPropertyChanged的基类对象的集合。我怀疑内存泄漏,并使用memprofiler对我的应用程序进行了分析,这证实了我的所有列表都从未被处理过,并且因为它们订阅了绑定列表的propertyChanged均衡器,所以它们一直保持不变。
这是我的对象的样本
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有人能帮我把名单处理掉吗。
谢谢大家
亨克你是对的。问题不在于我提到的代码,而是将其缩小到了阻止处理表单的代表。我正在工作的一个例子,以复制问题,我将上传到网站。谢谢
发布于 2009-07-05 11:49:30
我不认为问题在这里显示的代码中,BaseObject中的事件只会导致传出引用(对订阅者)。对于Add/Remove和BaseList类的隐藏,它变得有点模糊。是否<自定义Code>会干扰订阅/取消订阅PropertyChanged事件?
where T:BaseList是一个错误(我希望这里是baseObject ),还是涉及另一个类?
另外,我对“虚拟”中的“虚拟”感到有点困惑。
public virtual event PropertyChangedEventHandler PropertyChanged;我不确定你是否有这个目的,我认为它应该去。
而且BaseBusinessList应该实现IRaiseItemChangedEvents。
https://stackoverflow.com/questions/1083842
复制相似问题