Chuck Rittersdorf wrote:
> 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[i] = 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[i]; /* is this correct? "[]" after delete
> keyword. compiler accepts it.*/
> // or this
> delete pData[i]; // I think this is wrong but compiler
> accepts
> }
>
> delete pData;
>
> to summarize:
> is it:
>
> delete [] pData[i];
>
> or
>
> delete pData[i];
http://tinyurl.com/xjw7
--
Peter van Merkerk
peter.van.merkerk(at)dse.nl