Do you need to remove an event handler in the destructor?

后端 未结 9 1258
情书的邮戳
情书的邮戳 2021-01-31 01:22

I use some UserControls which get created and destroyed within my application during runtime (by creating and closing subwindows with these controls inside).
It

9条回答
  •  爱一瞬间的悲伤
    2021-01-31 01:59

    Event handlers are tricky and can easily hide a resource leak. As Tigran says. Use IDisposeable and forget about destructors. I recommend measuring whether you got it right. Just by looking at the memory consumption of your app in task manager will tell if a leak is present if you stress test it a little bit by loading up and closing a few thousand windows.

提交回复
热议问题