Interpreted differently, there's more complexity to this question than meets the eye.
Sure Disposed
gets called, but does it do anything? It depends.
If you've subscribed to the Disposed
event of a page or control and are banking on it being called per-request, you might be in for a surprise. Yes, technically speaking ProcessRequestCleanup()
calls it for you, but have a look at what it actually calls:
public virtual void Dispose()
{
IContainer service = null;
if (this.Site != null)
{
service = (IContainer) this.Site.GetService(typeof(IContainer));
if (service != null)
{
service.Remove(this);
EventHandler handler = this.Events[EventDisposed] as EventHandler;
if (handler != null)
{
handler(this, EventArgs.Empty);
}
}
}
if (this._occasionalFields != null)
{
this._occasionalFields.Dispose();
}
}
Without a design surface, this code essentially does nothing at run-time, meaning your Disposed
handlers will never execute.
Lesson is don't rely on Disposed
handlers to execute per request. You can override it to guarantee something executes, but Unloaded
is a much safer bet.