This causes a memory leak: Only memory of array
is freed, but memory reserved for cells is not freed before your program closes.
You should match each new
with a delete
:
for(int i=0; i<3;i++){
delete[] array[i];
}
delete[] array;
If you received the pointer from some function, you need to know its size to be able to free all the memory.
To avoid manual memory handling, you can either use vector of shared pointers (std::vector<std::shared_ptr<char>
) or in this specific case, use strings (std::vector<std::string>
).