I have a problem deleting class attributes inside the destructor of the class, if I try to do the same thing in a classic procedural program it works perfectly.
But if I try to execute the code below the destructor doesn't delete
"array" and doesn't free the memory:
class MyClass
{
private:
int *array;
int n = 2000000;
public:
MyClass(){
this->array = new int[n];
for(int i=0; i<n; i++){
array[i] = i;
}
}
~MyClass(){
delete[] array;
}
};
int main(int argc, const char * argv[])
{
MyClass *test = new MyClass;
delete test;
return 0;
}
Why?