If I have a model which is pretty much a readonly collection and dispayed on a grid, where the user selects a row.
Do I need to have INotifyPropertyChanged always implemented on the model? Is there a performance benefit of implementing vs not?
I would like to know if performance is impacted by UI trying to use something like
var x = Model as INotifyPropertyChanged;
which it wouldn't have used otherwise.
                        
If you are using the model in any data bindings, then yes, you should implement
INotifyPropertyChangedeven if it is completely immutable. The reason has nothing to do with performance, but to avoid a memory leak.A
Bindingwill always try to register for change notifications, and if you do not implementINotifyPropertyChangedor expose discrete change events of the form[Property]Changed, it will register through thePropertyDescriptorAPI. The default, reflection-basedPropertyDescriptorimplementation uses a global subscription table, and if for some reason theBindingdoes not unsubscribe cleanly, your view model will be kept alive indefinitely. This is in contrast to the weak event pattern used when bindings subscribe toINotifyPropertyChangednotifications. Bindings at runtime generally clean up after themselves, but the Xaml designer is notorious for leaking under these circumstances, causing your designer process's memory consumption to rise steadily as you work.