When you create an instance of a class, do you have to delete the
instance after you are finished with it? I can't seem to find any
information dealing with that. All I see is create the instance and
thats it.
Thanks
Keon
Ignacio Machin ( .NET/ C# MVP ) - 11 Jan 2008 17:12 GMT
Hi,
In general no, the GC will take care of that. The only difference is when
the class implement the IDisposable interface, these are classes that you
should call Dispose on when finished with them.

Signature
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
> When you create an instance of a class, do you have to delete the
> instance after you are finished with it? I can't seem to find any
[quoted text clipped - 4 lines]
>
> Keon
Michael Starberg - 11 Jan 2008 17:38 GMT
> When you create an instance of a class, do you have to delete the
> instance after you are finished with it? I can't seem to find any
[quoted text clipped - 4 lines]
>
> Keon
This is a very important and interesting question.
From the annals and history of computing,
memory allocation comes in different flavors.
1. Direct allocation. (remember malloc(int), anyone? *s*)
2. Reference Counting (The horrors of COM and IUnknown *s*)
3. Garbage Collecting (meow!)
4. GC + IDisposable (meow?)
Typically in .NET, all your references are fire-and-forget.
But not always. You really need to learn about reference types (classes) and
value types (structs) and why the latter is never/can't be Garbage
Collected.
Then you really must understand the IDisposable.Dispose() method and its
use. And the C# syntactic suggar using using.
Sit Vis Nobiscum
- Michael Starberg