Handles vs. AddHandler

前端 未结 7 424
花落未央
花落未央 2021-01-15 18:53

Is there an advantage to dynamically attaching/detaching event handlers?

Would manually detaching handlers help ensure that there isn\'t a reference remaining to a d

7条回答
  •  野的像风
    2021-01-15 19:21

    I find that dynamically attaching/detaching event handlers is only of use where you have a long-lived object exposes events that are consumed by many short-lived objects. For most other cases the two objects are disposed around the same time and the CLR does a sufficient job of cleaning up on its own

提交回复
热议问题