If the object implements IDisposable, call .Dispose if it's declared as public. Sometimes .Dispose is marked as protected (internal) and you can't call it, but make the effort if you can.
The difference is objects that contain unmanaged resources (network connections, file handles, database connections) typically implement IDisposable in order to release those unmanaged resources. Failing to call .Dispose results in the resource not being released until the next garbage collection cycle. In the case of things like Database connections, where you may be paying license fees on the number of active connections, that can get expensive. Or... other parts of your code will break because they can't gain access to a resource. A common error is not to dispose of file handles -- if you try and re-open the file, it will fail because .NET hasn't really closed it yet (GC cycle hasn't run yet).
Chip H.
If you want to get the best response to a question, please check out FAQ222-2244 first
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.