Suppose you have no control over the creation and deletion of objects. There are some circumstances when you do not.
Take an instance of MVC. Suppose you had something like this:
interface IFoo : IDisposable { }
class HomeController
{
private IFoo _foo = null;
HomeController(IFoo foo)
{
_foo = foo;
}
ActionResult Index()
{
return View(_foo);
}
}
As soon as your object is transferred to the view, you will largely lose control of it.
In this case, I can only think of two ways to mitigate this scenario:
1) If it hurts, do not do it. In other words, do not let what you give your ideas, IDisposables.
2) , 1, IDisposable , IDisposable . , , -, IDisposable, Dispose() . . :
ActionResult Index()
{
using(_foo)
{
return View((FooViewModel)_foo);
}
}
. MVC IDisposable , View, , ?