Ask Your Question

Revision history [back]

If you comment out the release function call, the memory is released because your variable Caimg1 is a local one, it will be free automatically. Your code contains error that can lead to a memory leak: CvMatND *Caimg1 = cvCreateMatND(2, new_size, CV_32F); this statement allocates a memory and Caimg1 points to that, but the next statement: cvReshapeMatND(&TpCa, sizeof(CvMatND), Caimg1, 0, 2, new_size); will make Caimg1 points to memory data of TpCa, this makes the memory unmanaged. Indeed, the function cvReshapeMatND create a new header matrix and changes the data pointer (see more at https://github.com/Itseez/opencv/blob/master/modules/core/src/array.cpp).

If you comment out the release function call, the memory is released because your variable Caimg1 is a local one, it will be free automatically. Your code contains error that can lead to a memory leak: CvMatND *Caimg1 = cvCreateMatND(2, new_size, CV_32F); this statement allocates a memory and Caimg1 points to that, but the next statement: cvReshapeMatND(&TpCa, sizeof(CvMatND), Caimg1, 0, 2, new_size); will make Caimg1 points to memory data of TpCa, this makes causes the memory unmanaged. Indeed, the function cvReshapeMatND create a new header matrix and changes the data pointer (see more at https://github.com/Itseez/opencv/blob/master/modules/core/src/array.cpp).