This question is much more related to C than OpenCV. For example, they:
CvScalar b1; CvScalar f; CvPoint pt;
are local variables, and therefore they are automatically deactivated when the { } region belonging to them finishes execution.
It:
CvPoint *point;
is a pointer and at the same time is a local variable. You should not delete or free() , because you did not allocate any memory for it through new or malloc() . This will cause a problem (possibly a malfunction).
But data on the other hand:
float *data = (float*)resd->imageData;
is a pointer and a local variable that contains a block of memory. However, this is unreasonable for delete[] data; or free(data) in this particular case, because you did not allocate this memory directly. Obviously, this memory was allocated as part of resd , which means that you need to check the code and find out how the resd variable was declared / initialized, and then follow the appropriate procedure to release it. Since I know the litle bit about OpenCV, I can say that resd is IplImage* . If you used cvCreateImage() to create this variable, then it is also your task to free it with cvReleaseImage() .
Finally:
CvPoint* ptsCorner=(CvPoint*) malloc(3*sizeof(ptsCorner[0]));
This is a typical case of dynamic memory allocation, where you specifically allocate memory. Since ptsCorner is a local variable and a pointer, when the region to which it belongs finishes executing, you will lose a reference to this memory block and it will simply be lost in your RAM, free up memory space and cause a leak. Needless to say, you must execute free() to free memory in this case.
source share