Should I Dispose() DataSet and DataTable?

DataSet and DataTable both implement IDisposable, so, by conventional best practices, I should call their Dispose() methods. However, from what I’ve read so far, DataSet and DataTable don’t actually have any unmanaged resources, so Dispose() doesn’t actually do much. Plus, I can’t just use using(DataSet myDataSet…) because DataSet has a collection of DataTables. So, to … Read more

Do HttpClient and HttpClientHandler have to be disposed between requests?

System.Net.Http.HttpClient and System.Net.Http.HttpClientHandler in .NET Framework 4.5 implement IDisposable (via System.Net.Http.HttpMessageInvoker). The using statement documentation says: As a rule, when you use an IDisposable object, you should declare and instantiate it in a using statement. This answer uses this pattern: var baseAddress = new Uri(“http://example.com”); var cookieContainer = new CookieContainer(); using (var handler = new … Read more

Proper use of the IDisposable interface

I know from reading the Microsoft documentation that the “primary” use of the IDisposable interface is to clean up unmanaged resources. To me, “unmanaged” means things like database connections, sockets, window handles, etc. But, I’ve seen code where the Dispose() method is implemented to free managed resources, which seems redundant to me, since the garbage … Read more