How do static events compare to non-static events in C#?

后端 未结 5 677
误落风尘
误落风尘 2020-12-31 05:47

I just realized static events exist - and I\'m curious how people use them. I wonder how the relative comparison holds up to static vs. instance methods. For instance, a s

5条回答
  •  渐次进展
    2020-12-31 06:29

    Be wary of static events. Remember that, when an object subscribes to an event, a reference to that object is held by the publisher of the event. That means that you have to be very careful about explicitly unsubscribing from static events as they will keep the subscriber alive forever, i.e., you may end up with the managed equivalent of a memory leak.

提交回复
热议问题