How can I clear event subscriptions in C#?

前端 未结 10 1906
野趣味
野趣味 2020-11-30 18:43

Take the following C# class:

c1 {
 event EventHandler someEvent;
}

If there are a lot of subscriptions to c1\'s someEven

10条回答
  •  臣服心动
    2020-11-30 19:15

    Setting the event to null inside the class works. When you dispose a class you should always set the event to null, the GC has problems with events and may not clean up the disposed class if it has dangling events.

提交回复
热议问题