G
Guest
I'm curious if anyone knows why the C# and VB.NET compilers don't
automatically call Dispose() on objects that support IDisposable when they
go out of scope.
I asked a co-worker and his response was that IDisposable is a library
feature and not a language feature. To which I pointed out that the using()
statement calls Dispose() and foreach uses IEnumerator.
So why leave it to developers to screw up when the compiler could
conceivable take care of it for you?
Are there situations when you'd call Dispose() but not want to let the
object go out of scope? I can't think of a single situation. Is there some
other reasoning behind it?
Pete
automatically call Dispose() on objects that support IDisposable when they
go out of scope.
I asked a co-worker and his response was that IDisposable is a library
feature and not a language feature. To which I pointed out that the using()
statement calls Dispose() and foreach uses IEnumerator.
So why leave it to developers to screw up when the compiler could
conceivable take care of it for you?
Are there situations when you'd call Dispose() but not want to let the
object go out of scope? I can't think of a single situation. Is there some
other reasoning behind it?
Pete