A CustomPropertyList class is created in my form constructor.
form(String ^s)
{
InitializeComponent();
CustomPropertyList ^propertyList = gcnew CustomPropertyList(s);
...
The CustomPropertyList class has a destructor
CustomPropertyList::~CustomPropertyList()
{
if (MessageBox::Show("Do you want to save your changes?","Editin",MessageBoxButtons::YesNo)==DialogResult::Yes)
...
Why is it not called when the program exits? (I know it’s not as I don’t see the message box and there’s a breakpoint there)
I’m very grateful for any help
Because this is not destructor, this is Dispose method (in C# terms). If client doesn’t call Dispose, it is never called. On the other hand, finalizer (!CustomPropertyList) should be called, unless GC::SuppressFinalize is used to prevent it.
From C# code, ~CustomPropertyList can be called by using Dispose. From C++/CLI client code, it can be called by using delete operator.
See more details in this C++/CLI guru article: http://www.codeproject.com/KB/mcpp/cppclidtors.aspx