开发者

Should I implement IDisposable for a User Control?

I am c开发者_JS百科reating a .NET User Control. Do I need to implement the IDisposable interface for my User Control?


Control already implements IDisposable

You only need to override the implementation if you need to dispose some unmanaged resources.

So the simple answer: no, probably not.


Actually, Control already implements IDisposable. The base implementation is usually generated in the .Designer.cs file if you did any sort of auto-generation of the Control using Visual Studio. You just need to add to the base implementation if you need to.

It has a virtual Dispose method which takes a boolean flag. If True, then Dispose was called via the interface. If False, then Dispose was called via the finalizer.


Only if you have external resources that need to be released quickly. Otherwise, those resources may be held on to for as long as the object remains uncollected, and possibly longer than that.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜