This documentation is archived and is not being maintained.

auto_gcroot::~auto_gcroot 

The auto_gcroot destructor.


~auto_gcroot();

The destructor also destructs the owned object.

// 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" );
}

Output

ClassA constructor
ClassA destructor
done

Header file <msclr\auto_gcroot.h>

Namespace msclr

Show: