Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
End of 2001?
Message
De
03/04/2001 04:47:54
 
 
À
01/04/2001 07:06:27
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Divers
Thread ID:
00490436
Message ID:
00491217
Vues:
9
In a C++ class you can define, or let the C++ compiler generate a default destructor. For example the following snippet shows a simple class with a constructor and destructor (the destructor being indicated by ~ prefix).
class CSampleClass
{
public:
   CSampleClass();          // Constructor.

protected:
   ~CSampleClass();         // Destructor.

public:
   char *string;            // Sample class member.
}

CSampleClass::CSampleClass()
{
   // Allocate memory for our string.
   string = new char[10];
}

~CSampleClass::CSampleClass()
{
   // Make sure the heap is recovered.
   delete [] string; 
}
As you can see when an instance of this class goes out of scope the heap allocated to the string pointer will be reclaimed. This is the point to C++ destructors, you know EXACTLY when each objects destructor is called. However in a garbage collected environment this becomes difficult (sometimes impossible) to do so we can't rely on Finalize being called at a deterministic point. C# will apparently provide this functionality using a Dispose() method when Beta 2 ships.

Again if you dig deep into the CRT source (specifically cinitexe.c) you can begin to understand this a little better. The constructor's are created as a static array of function pointers with little bits of code emitted by the compiler that index into this.

Again this isn't a big problem, Beta 2 will provide the functionality require, however the question to ask is:-

"is it in the CLR or is this a C# specific feature?"
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform