开发者

Is unhooking event handlers needed in ASP.NET to prevent memory leaks?

Coming from WinForms/WPF I've learned the hard way that not remembering to unhook event handlers can lead to memory leaks.

Does this apply to Webapps t开发者_开发百科oo? It seems like when the request ends, everything (non-static) should be eligible for garbage collection. Is that true?

I remember jumping through all sorts of hoops to ensure that events got unhooked when an object goes out of scope, especially with multi-threading going on to ensure a responsive UI. Is all of that still necessarily in a webapp or is that one of the luxuries of working with a (mostly) RESTful model?


I don't think you need to worry about unhooking events. You are correct that everything non-static gets queued up for garbage collection. The main thing to worry about is cleaning up unmanaged code. Make sure you wrap everything implementing IDisposable in a using{} block (or manually call Dispose() on it).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜