When PropertyChangedEventManager created/attached

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?

  • When Patient is created
  • When WPF binds to Patient property
  • Some other point.

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.

转载于:https://my.oschina.net/u/138995/blog/184254

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值