C
Chuck Rittersdorf
What is the correct form of delete when deleting
a dynamic block of memory?
// I am allocating 2D dynamic arrays in the following way.
int *pData;
pData = new int *[No_Rows];
for( int i = 0; i < No_Rows; i++)
pData = new int[No_Cols];
// now for deleting it
// this is what i am not sure about. Compiler accepts it and
// program runs with no obvious problems, but i am worried
// i may be causing some kind of memory leak.
for( i = 0; i < No_Rows; i++){
delete [] pData; /* is this correct? "[]" after delete
keyword. compiler accepts it.*/
// or this
delete pData; // I think this is wrong but compiler
accepts
}
delete pData;
to summarize:
is it:
delete [] pData;
or
delete pData;
Thanks.
a dynamic block of memory?
// I am allocating 2D dynamic arrays in the following way.
int *pData;
pData = new int *[No_Rows];
for( int i = 0; i < No_Rows; i++)
pData = new int[No_Cols];
// now for deleting it
// this is what i am not sure about. Compiler accepts it and
// program runs with no obvious problems, but i am worried
// i may be causing some kind of memory leak.
for( i = 0; i < No_Rows; i++){
delete [] pData; /* is this correct? "[]" after delete
keyword. compiler accepts it.*/
// or this
delete pData; // I think this is wrong but compiler
accepts
}
delete pData;
to summarize:
is it:
delete [] pData;
or
delete pData;
Thanks.