pglazkov / MvvmValidation

Lightweight library that helps reduce boilerplate when implementing validation in XAML MVVM applications
MIT License
167 stars 31 forks source link

Memory Leak #29

Closed jmartincaro closed 3 years ago

jmartincaro commented 3 years ago

NotifyDataErrorInfoAdapter produces a memory leak I think because of

Validator.ResultChanged += (o, e) => OnValidatorResultChanged(o, e, errorsChangedNotificationContext);

this generate event handler leak because at no time is it done

Validator.ResultChanged -=(o, e) => OnValidatorResultChanged(o, e, errorsChangedNotificationContext);

pglazkov commented 3 years ago

Thank you for reporting this issue. Indeed, this would cause a memory leak. Normally, this is not a problem because in typical usage the lifetime of NotifyDataErrorInfoAdapter is the same as the adapted ValidationHelper instance, but I can see that you might want to have one shared instance of ValidationHelper.

Would it help if I make NotifyDataErrorInfoAdapter implement IDisposable, so that you can call Dispose whenever you are done with the instance? I just published a new "Beta" version that implements this: https://www.nuget.org/packages/MvvmValidation/3.1.2-Beta1. Could you test it and let me know if it works for your use case?

jmartincaro commented 3 years ago

Thank you very much for reply. Works fine with update. Thank you.