Destructor demo
#include "stdafx.h" using namespace System; using namespace System::IO; ref class MyClass { public: MyClass() { Closed = false; } ~MyClass() { if ( !Closed ) Close(); } void Close() { // Release unmanaged resources Closed = true; } private: bool Closed; }; void main() { MyClass^ myObject = gcnew MyClass(); try { // Do something } finally { // Calls destructor delete myObject; } }