Partager via


auto_gcroot::~auto_gcroot

 

The latest version of this topic can be found at auto_gcroot::~auto_gcroot.

The auto_gcroot destructor.

Syntax

~auto_gcroot();  

Remarks

The destructor also destructs the owned object.

Example

// msl_auto_gcroot_dtor.cpp  
// compile with: /clr  
#include <msclr\auto_gcroot.h>  
  
using namespace System;  
using namespace msclr;  
  
ref class ClassA {  
public:  
   ClassA() { Console::WriteLine( "ClassA constructor" ); }  
   ~ClassA() { Console::WriteLine( "ClassA destructor" ); }  
};  
  
int main()  
{  
   // create a new scope for a:  
   {  
      auto_gcroot<ClassA^> a = gcnew ClassA;  
   }  
   // a goes out of scope here, invoking its destructor  
   // which in turns destructs the ClassA object.  
  
   Console::WriteLine( "done" );  
}  
ClassA constructor  
ClassA destructor  
done  

Requirements

Header file <msclr\auto_gcroot.h>

Namespace msclr

See Also

auto_gcroot Members
auto_gcroot::release
auto_gcroot::auto_gcroot