c++ - Proper way of deleting a char** array -


i have dynamically allocated char** array private member in 1 of classes.

the first allocation occurs according number of words

client_interests = new char* [n]; 

later each index of array allocated according length of word + 1

char[i] = new char [strlen(word)+1]; 

would proper way of deallocating memory of member (the classes dtor calling function)?

void client::deallocate() {     int i;     (i = 0; < n; ++) //loops through each word     {         delete [] client_interests[i]; //each word array of characters, hence delete [] used     }     delete [] client_interests; //deallocating pointer     client_interests = null; } 

thaks!

your code correct. since allocate using new [], de-allocating delete [] required. also, de-allocating in reverse order - inner arrays first, outer array - required.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -