I’ve got an array of pointers as a member in my class.
I am using those pointers to allocate a certain number of buffers.
In the destructor I want to free this memory, but it seems like I am doing something wrong.
//In the Constructor
for(int i = 0; i< NUM_OF_BUFFERS; i++)
{
mBuffer[i] = new Uint8[BUFFERSIZE];
memset(mBuffer[i], 0, BUFFERSIZE);
mBufferState[i] = NULL;
}
//In the destructor
for (int i = 0; i < NUM_OF_BUFFERS; i++)
{
delete[] mBuffer[i];
}
For some reason this doesn’t seem to work.
If I am commenting those lines in the destructor out, the program runs fine, if I run it with those lines it seems to freeze.
There doesn’t appear to be anything wrong with the code you posted, so the problem must be somewhere in the code you didn’t post.
My bet would be on some out-of-bounds access that is clobbering the bookkeeping information required by the heap manager.