Do I need to unsubscribe from (manually subscribed to) events in asp.net?

后端 未结 2 1772
鱼传尺愫
鱼传尺愫 2020-12-20 22:02

Do the same best practis rules regarding subscribing/unsubscribing to events apply in asp.net?

I know it might seem like a silly question, but when I think about it,

2条回答
  •  没有蜡笔的小新
    2020-12-20 22:20

    The page instance and all of its components will "go out of scope" when request completes, e.g. they become eligible for GC. So your ListView will go out of scope along with the Page/user controls on it. You don't need to unsubscribe (unless you subscribe to an event that belongs to some kind of singleton that survives every request and use one of the methods of the page as the event handler, for example).

    The same thing is valid for the presenter (again as long as this presenter is used solely with one page and goes out of scope after that).

提交回复
热议问题