Handles vs. AddHandler

前端 未结 7 429
花落未央
花落未央 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:12

    Manually detaching an event can be important to prevent memory leaks: the object that connects to an event fired by another object, will not be garbage collected until the object that fires the event is garbage collected. In other words, an "event-raiser" has a strong reference to all the "event-listeners" connected to it.

提交回复
热议问题