I have experienced some memory managment ambiguitys with opencv. You could do this with the new opencv c++ classes:
cv::Mat theimage = cvLoadImage(\"rawimag
The ambiguity comes from an extremelly horrible practice: mixing the C interface with the C++ interface of OpenCV. Don't do it, use cv::imread()
instead.
The destructor of cv::Mat
will always deallocate memory when needed, except when it is initialized from a IplImage, then it's up to you to free it's resources with deallocate()
. I wrote a simple experiment to verify this information:
void load()
{
cv::Mat img = cvLoadImage("out.png", 1);
std::cout << "* IMG was loaded\n";
getchar();
img.deallocate();
}
int main()
{
load();
std::cout << "* IMG was deallocated\n";
getchar();
return 0;
}
The getchar()
calls pause the program so you can check the memory footprint of the application. If you comment out deallocate()
you'll notice that the memory footprint doesn't decrease after loading the image.
On a side note, Mat::release() only decreases the reference counter and deallocates the data if needed (but it will also not deallocate in case the Mat
was initialized from IplImage
).