Does ASP.Net call Dispose on the Page/Controls in a page, or must I do this?

前端 未结 4 672
小蘑菇
小蘑菇 2020-12-18 21:01

Given that the Control class implements IDisposable, I would think that ASP.Net is at least capable of triggering a Dispose cascade as the Page finishes it\'s life-cycle on

4条回答
  •  鱼传尺愫
    2020-12-18 21:25

    No, you should not call Dispose on controls, that is being done. You are responsible for other Disposable objects you create outside the Control structure (FileStreams etc).

    This follows from a general .NET principle: The Page is the owner of the Controls and therefore required to cascade the (explicit) Dispose to them. For the actual code you will have to Reflector the code for Web.UI.Control.

提交回复
热议问题