4

When using IDbCommand, IDataReader, or DataTable, can you depend on the destructor to dispose resources, or will these objects leak resources if dispose is not called directly?

Jon Ediger
  • 949
  • 1
  • 10
  • 27

1 Answers1

4

They don't leak, but they will consume resources until they are garbage collected. The GC will call Dispose() on them. I don't think DataTable maintains a connection to the database, so you wouldn't have to worry about calling Dispose() or Close() on it.

See my answer here to a similar question.

Community
  • 1
  • 1
wprl
  • 24,489
  • 11
  • 55
  • 70