C# – Is is necessary to dispose DbCommand after use


We use Enterprise Library 3.0 to access Oracle DB (microsoft oracle client).
What happens when I do not dispose a DbCommand instance after a stored procedure or function is called? Does .NET automatically garbage collect them?
Note that we do make sure that the transaction/connection gets closed and disposed properly.

Best Solution

This is a duplicate, but I don't have time to find the original.

If it implements IDisposable, and if you created it, then you need to call Dispose on it. That's why the developer of the class made it implement IDisposable.

The garbage collector does not call Dispose on all IDisposable-implementing objects.