Ask Your Question
3

how to free memory through cv::Mat ?

asked 2013-05-30 07:33:15 -0600

mrgloom gravatar image
IplImage* src= cvLoadImage("1.tif");
        Mat m= src;//no copy
        Mat m1(src);//no copy
        m.release();//don't free mem
        m1.release();//don't free mem
        cvReleaseImage(&src);//free mem

how to free memory through cv::Mat ?

edit retag flag offensive close merge delete

Comments

Why would you wantt to do that?

Ben gravatar imageBen ( 2013-05-30 08:08:28 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
12

answered 2013-05-30 08:05:52 -0600

Vladislav Vinogradov gravatar image

updated 2013-05-30 08:10:49 -0600

Use cv::imread, this function returns cv::Mat

Mat src = imread("1.tif");
src.release(); // free mem

cv::Mat will free memory only if it was allocated by create method (if Mat object owns this memory):

Mat src(100, 100, CV_32FC1);
src.release(); // will free memory

When you create Mat object from your pointer or from old C structs (CvMat, IplImage), Mat object will not free this memory.

float* data = new float[100 * 100];
Mat src(100, 100, CV_32FC1, data);
src.release(); // will not free memory
delete [] data;
edit flag offensive delete link more

Comments

Yes, i have already understand it. But it's confusing when you create IplImage* and then use it with cv::Mat. Now I also use cv::Ptr<> to not to worry about cvReleaseImage.

mrgloom gravatar imagemrgloom ( 2013-05-31 00:58:03 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2013-05-30 07:33:15 -0600

Seen: 85,018 times

Last updated: May 30 '13