Classes

  • Thread starter Thread starter Keon
  • Start date Start date
K

Keon

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
 
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.
 
Keon said:
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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top