P
Peter Hemmingsen
Hi,
Below is a smal test program which create two objects deriving from
DataTable.
When running the 3 lines of code marked as Ex1 the destructor of DataTableEx
is never called,- why?
When running the 2 lines of code marked as Ex2 the first line fail
compilation claiming there is no destructor,- why ? (the second one force by
destructor to be called)
The documentation I've read says that the compiler will "wrap" my destructor
into a finalize method that should be called my the gc.
Your help is highly appreciated,- thanks
Peter Hemmingsen
#using <mscorlib.dll>
#using <System.dll>
#using <System.Data.dll>
using namespace System:ata;
public __gc class DataTableEx : public DataTable {
public:
DataTableEx()ataTable() {
System::Console::Write ("DataTableEx created\n");
};
~DataTableEx() {
System::Console::Write ("DataTableEx destroyed\n");
};
};
void main () {
DataTable* dt=new DataTableEx();
DataTableEx* dtex=new DataTableEx();
// ex 1
dt=0;
dtex=0;
System::GC::Collect();
// ex 2
delete dt; // compiler fails !!!
delete dtex;
}
Below is a smal test program which create two objects deriving from
DataTable.
When running the 3 lines of code marked as Ex1 the destructor of DataTableEx
is never called,- why?
When running the 2 lines of code marked as Ex2 the first line fail
compilation claiming there is no destructor,- why ? (the second one force by
destructor to be called)
The documentation I've read says that the compiler will "wrap" my destructor
into a finalize method that should be called my the gc.
Your help is highly appreciated,- thanks
Peter Hemmingsen
#using <mscorlib.dll>
#using <System.dll>
#using <System.Data.dll>
using namespace System:ata;
public __gc class DataTableEx : public DataTable {
public:
DataTableEx()ataTable() {
System::Console::Write ("DataTableEx created\n");
};
~DataTableEx() {
System::Console::Write ("DataTableEx destroyed\n");
};
};
void main () {
DataTable* dt=new DataTableEx();
DataTableEx* dtex=new DataTableEx();
// ex 1
dt=0;
dtex=0;
System::GC::Collect();
// ex 2
delete dt; // compiler fails !!!
delete dtex;
}