开发者

WeakEvent garbage collection in C#

开发者 https://www.devze.com 2023-04-13 08:37 出处:网络
I\'m thinking today at the following scenario: I have two classes A and B. A exp开发者_如何学Coses an event E.

I'm thinking today at the following scenario:

I have two classes A and B.

A exp开发者_如何学Coses an event E.

B subscribes to this event "E", using a weak event handler "W".

After a while nobody holds any reference to B, but the GC has not yet kicked in.

While B is not yet collected by the GC and A raises "E", will the weak event handler be called?

I'm thinking yes, but I'm curios if I'm not missing something.


Yes it will. The WeakEventManager will see that the object B references is 'alive' (not yet collected) and will raise the event there.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号