Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

opencv namedWindow leak ( c++ and opencv )

Tags:

c++

opencv

Running valgrind, I get loads of memory leaks in opencv, especially with the function of namedWindow.

In the main, I have an image CSImg and PGImg:

std::string cs = "Computer Science Students";
std::string pg = "Politics and Government Students";
CSImg.displayImage(cs);
cv::destroyWindow(cs);
PGImg.displayImage(pg);
cv::destroyWindow(pg);

display image function is:

void ImageHandler::displayImage(std::string& windowname){
namedWindow(windowname);
imshow(windowname, m_image);
waitKey(7000);

}

Valgrind is giving me enormous memory leaks when I do displayImage. For example:

==6561== 2,359,544 bytes in 1 blocks are possibly lost in loss record 3,421 of 3,421
==6561==    at 0x4C2B3F8: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6561==    by 0x4F6C94C: cv::fastMalloc(unsigned long) (in /usr/lib/libopencv_core.so.2.3.1)
==6561==    by 0x4F53650: cvCreateData (in /usr/lib/libopencv_core.so.2.3.1)
==6561==    by 0x4F540F0: cvCreateMat (in /usr/lib/libopencv_core.so.2.3.1)
==6561==    by 0x56435AF: cvImageWidgetSetImage(_CvImageWidget*, void const*) (in /usr/lib/libopencv_highgui.so.2.3.1)
==6561==    by 0x5644C14: cvShowImage (in /usr/lib/libopencv_highgui.so.2.3.1)
==6561==    by 0x5642AF7: cv::imshow(std::string const&, cv::_InputArray const&) (in /usr/lib/libopencv_highgui.so.2.3.1)
==6561==    by 0x40CED7: ImageHandler::displayImage(std::string&) (imagehandler.cpp:33)
==6561==    by 0x408CF5: main (randomU.cpp:601)

imagehandler.cpp, line 33 is:

imshow(windowname, m_image); //the full function is written above ^

randomU.cpp line 601 is:

CSImg.displayImage(cs);

Any help is appreciated. Ask for any further info you need.

like image 362
TheNotMe Avatar asked Nov 21 '12 17:11

TheNotMe


1 Answers

Sorry, the stark reality looks like OpenCV leaks. It leaks from the side of its Qt interface too due to self-references according to the Leaks Instrument (XCode tools).

Other proof that this is not just a false alarm: On my Mac, Opencv 2.4.3 continuously grows in the memory (according to Activity Monitor) when processing webcam input. (I am not using any pointers or data strorages so theoretically my OpenCV program should remain of constant size.)

like image 106
Barney Szabolcs Avatar answered Oct 06 '22 02:10

Barney Szabolcs