#include "stdafx.h"
#include
using namespace System;
using namespace msclr;
ref class MyObject : public IDisposable
{
private:
String^ Name;
public:
MyObject(String^ name) : Name(name)
{
Console::WriteLine("Constructor - {0}", Name);
}
~MyObject()
{
Console::WriteLine("Destructor - {0}", Name);
Name = nullptr;
}
protected:
!MyObject()
{
Console::WriteLine("Finalize - {0}", Name);
Name = nullptr;
}
};
int main(array ^args)
{
{
MyObject^ NonAuto = gcnew MyObject("Non Auto no finally");
}
MyObject^ NonAutoWFinally;
try
{
NonAutoWFinally = gcnew MyObject("Non Auto with finally");
}
finally
{
delete NonAutoWFinally;
}
{
auto_handle Auto = gcnew MyObject("Auto");
}
return 0;
}