To make a very long story short… This is in a large WPF project
I have a class “Patient” that implements INotifyPropertyChanged
. When I dispose this class I am checking that the PropertyChangedEventHandler
is null and if not run it to a ListenerDetector
class that logs the listeners so we can track them down and clean the leaks. Patient does have some properties that are bound to WPF elements as well as other objects the use its PropertyChanged
to monitor changes.
After disposing everything else, my log result is as follows:
Log: Patient still has the following listener(s) attached: -
System.ComponentModel.PropertyChangedEventManager
Question:
When is the PropertyChangedEventManager
created?
If Patient.PropertyChangedEventHandler
is set to null
and therefore disconnected from the PropertyChangedEventManager
is there any way to recreate the Manager and have it listen to the Patient.PropertyChangedEventHandler
again? Please don’t ask why this would happen, that is a point of tension here :-(
The PropertyChangedEventManager
is created by WPF in order to support binding to any class that implements INotifyPropertyChanged
. It'll be created and used as soon as you bind to any class that implements INotifyPropertyChanged
.
That being said, its an implementation of the WeakEventManager pattern. While it's still showing a listener attached, realize that this listener is attached using the Weak Event Pattern. This will go away as soon as a full garbage collection occurs, as it's using weak references to hold the subscription. As such, this particular subscription shouldn't be the cause of a (long term) memory leak.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With