Cleaning up pointers and quitting app


suppose in a class I create an array
float *myarray

and initialise it
myClass() {
myarray = new float[10];

and the destructor calls:
~myClass (){
delete[] myarray;

when I run the app, and quit (apple-Q) I find I get a pointer freed was not allocated error. But pressing stop (top left in X-Code is fine).

Is what I’m doing correct?

How should I understand what quitting the app is doing? Clearly some kind of error here, but I don’t see what’s wrong yet in this way of doing it.

don’t use new, instead you can use a fixed size array like:

float myarray[10]

or use a vector instead of an array like:

vector<float> myarray;


then you won’t need any destruction.

or if you are using the nightly builds you can also use an std::array like:

std::array<float,10> myarray;