这两种实现有区别吗?
1:
public class SMSManager : ManagerBase
{
private EventHandler<SheetButtonClickEventArgs> _buttonClickevent;
public SMSManager(DataBlock smsDataBlock, DataBlock telephonesDataBlock) :
base(smsDataBlock)
{
_buttonClickevent = new EventHandler<SheetButtonClickEventArgs>(OnButtonClick);
SheetEvents.ButtonClick += _buttonClickevent;
}
public override void Dispose()
{
base.Dispose();
if (_buttonClickevent != null)
SheetEvents.ButtonClick -= _buttonClickevent;
}
}
2:
public class SMSManager : ManagerBase
{
public SMSManager(DataBlock smsDataBlock, DataBlock telephonesDataBlock) :
base(smsDataBlock)
{
SheetEvents.ButtonClick += new EventHandler<SheetButtonClickEventArgs>(OnButtonClick);
}
public override void Dispose()
{
base.Dispose();
SheetEvents.ButtonClick -= new EventHandler<SheetButtonClickEventArgs>(OnButtonClick);
}
}
在内存泄漏方面,第一个似乎比第二个更正确。但它真的正确吗?