Top "Dispose" questions

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources

What is the difference between using IDisposable vs a destructor in C#?

When would I implement IDispose on a class as opposed to a destructor? I read this article, but I'm still …

c# .net dispose destructor
How do I add Dispose functionality to a C# UserControl?

I have a class which implements UserControl. In .NET 2005, a Dispose method is automatically created in the MyClass.Designer.cs …

c# user-controls dispose
returning in the middle of a using block

Something like: using (IDisposable disposable = GetSomeDisposable()) { //..... //...... return Stg(); } I believe it is not a proper place for a return statement, …

c# dispose idisposable using-statement
Will a using clause close this stream?

I've apparently worked myself into a bad coding habit. Here is an example of the code I've been writing: using(…

c# filestream dispose streamreader
Datatable.Dispose() will make it remove from memory?

I have researching through very simple code and get stuck on seeing the dispose() result of datatable Following is the …

c# winforms dispose system.data.datatable
How does one tell if an IDisposable object reference is disposed?

Is there a method, or some other light-weight way, to check if a reference is to a disposed object? P.…

c# .net dispose idisposable
How and when are c# Static members disposed?

I have a class with extensive static members, some of which keep references to managed and unmanaged objects. For instance, …

c# .net dispose idisposable
Dispose, when is it called?

Consider the following code: namespace DisposeTest { using System; class Program { static void Main(string[] args) { Console.WriteLine("Calling Test"); Test(); …

c# .net garbage-collection dispose idisposable
Is there any way to close a StreamWriter without closing its BaseStream?

My root problem is that when using calls Dispose on a StreamWriter, it also disposes the BaseStream (same problem with …

c# stream dispose
Does SqlCommand.Dispose close the connection?

Can I use this approach efficiently? using(SqlCommand cmd = new SqlCommand("GetSomething", new SqlConnection(Config.ConnectionString)) { cmd.Connection.Open(); // set …

.net garbage-collection dispose sqlconnection sqlcommand