Say I have a Client object that has a child StatusType object. Both implement INotifyPropertyChanged.
The client subscribes to the event with the changed value in the property after checking the zero value and the value of the confident value
public StatusType Status
{
get { return _status ?? (_status = this.GetNewStatusType()); }
set
{
if (!(_status ?? (_status = this.GetNewStatusType())).Equals(value))
{
_status.PropertyChanged -= Status_PropertyChanged;
_status = value;
_status.PropertyChanged += Status_PropertyChanged;
base.OnPropertyChanged("Status");
}
}
}
The client listens for changed property events and creates bubbles.
void Status_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnPropertyChanged("Status." + e.PropertyName);
}
Both clients and StatusType inherit from EntitiesBase, which makes the actual heavy lifting of the implementation of INotifyPropertyChanged.
So my actual question is: do I need to unsubscribe from the StatusType.PropertyChanged event for memory reasons? If so, should I use a deconstructor or have an implementation of an IDisposable client?
If I were to use a deconstructor, would it look something like this?
~Client()
{
if (_status != null)
{
_status.PropertyChanged -= Status_PropertyChanged;
_status = null;
}
}
. , 1000 , , .