What is the best practice to dispose IDisposable
members of an ASP.net page?
Should I, ...
- use the
Page_Unload(object sender, EventArgs e)
event - override the
void Dispose()
method of theControl
class - something else ...
??
What is the best practice to dispose IDisposable
members of an ASP.net page?
Should I, ...
Page_Unload(object sender, EventArgs e)
eventvoid Dispose()
method of the Control
class??
Ideally there shouldn't really be any. In an ASP.NET page you should really use the using(...) { ... }
construct, which disposes objects immediately. If you have members of your page that need disposing, that's probably an indication of bad design, so consider putting those objects in things like session state or the cache instead.
If you absolutely have to have IDisposable objects as members of the page then I would go with during the Unload phase: