c++ - Delete a pointer to pointer (as array of arrays) -


i have in code:

double** desc = new double* [size_out]; (int = 0; < size_out; i++)     desc[i] = new double [size_in]; 

how delete desc?

should do:

delete [] desc; 

or

for (int i=0; i<size_out; i++)     delete [] desc[i]; delete [] desc; 

or

for (int i=0; i<size_out; i++)     delete [] desc[i]; delete desc; 

?

simple rules follow:

  • for each allocation, there has deallocation (ex1 therefore wrong)
  • what allocated using new should freed using delete, using new[] should deallocated using delete[] , using malloc should deallocated using free (ex3 therefore wrong)

conclusion, ex2 ok.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -