This might sound like a silly question, but I couldn’t find information on how to properly release memory in this case:
Assume there is a function returning a double* (there is no other information available about this function). Assume further the following use case:
for (int i = 0; i < SIZE; i++) {
double *ptr = new double[3];
/// do something with ptr, e.g., print
// delete[] ptr;
}
How does one correctly release memory in this case, since a delete[] ptr; placed in the comment above causes a backtrace (why?)?
Many thanks!
Doing
is quite right. So your problem must reside somewhere else. I can recommend using a debugger to check what’s going on, and if you’re on a linux system I would recommend trying valgrind/helgrind – it’s pretty nice