Memory Leak in imshow (on Windows)? (Bug #2138)
Description
Hello OpenCV-Team
Upgrading from 2.3.1 to 2.4.1 produced memory leaks which were not there before. It looks like the source is function 'double cv::threshold(...)' (imgproc, thresh.cpp).
As a workaround, we enabled the functions thresh_8u (16, 32), which where commented out and disabled all parallel_for(... ThresholdRunner ...) calls. That solved the problem (for now).
Regards,
Robin
Associated revisions
Merge pull request #2138 from alekcac:python_tutorial_fix
History
Updated by Kirill Kornyakov over 12 years ago
Could you please attach a sample code which shows the memory leak?
- Category set to imgproc, video
- Assignee set to Kirill Kornyakov
Updated by Robin Kaiser over 12 years ago
Hi Kirill,
this snippet should do the job:
byte m1[3][3] = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9}, }; byte m2[3][3]; CvMat mat1 = cvMat(3, 3, CV_8U, m1); CvMat mat2 = cvMat(3, 3, CV_8U, m2); cvThreshold(&mat1, &mat2, 5, 1, CV_THRESH_BINARY);
Updated by Vadim Pisarevsky over 12 years ago
I checked the source code of cvThreshold and cv::threshold. There are no any memory allocations inside, therefore memory leak is impossible. The bug should be somewhere in the code that calls cvThreshold.
- Status changed from Open to Cancelled
- Assignee changed from Kirill Kornyakov to Vadim Pisarevsky
Updated by Norman Link over 12 years ago
Hello,
I can confirm memory leaks using cv::threshold. In the following minimal example (using Visual Studio and it's built-in memory leak detection), the leaked memory sums up to about 10,5 kB, independent of the image size:
#define _CRTDBG_MAP_ALLOC #include <crtdbg.h> #include <iostream> #include <opencv2\opencv.hpp> using namespace std; int main() { _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); cv::Mat image(480, 640, CV_8UC1); image.setTo(0); cv::threshold(image, image, 127, 255, cv::THRESH_BINARY); cv::imshow("Test", image); while (cv::waitKey(1) != 27) {}; return 0; }
Updated by Vadim Pisarevsky over 12 years ago
looks like several people observed this problem; need to investigate.
- Status changed from Cancelled to Open
- Target version set to 3.0
Updated by Akos Marton about 12 years ago
No memory leak was found regarding the source attached. Verified by valgrind, so I tested it under Linux.
I think the cv::imshow() causes the problem, but can't see why. Tested with the latest snapshot.
//#include <crtdbg.h> #include <iostream> #include <opencv2/opencv.hpp> //#include <opencv2\opencv.hpp> using namespace std; int main() { // _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); cv::Mat image(480, 640, CV_8UC1); image.setTo(0); cv::threshold(image, image, 127, 255, cv::THRESH_BINARY); // cv::imshow("Test", image); // while (cv::waitKey(1) != 27) {}; return 0; }
- File 2138.cpp added
Updated by Vadim Pisarevsky about 12 years ago
so it may be some one-time memory leak in cv::imshow on Windows. Therefore, I change the subject and lower priority of the bug
- Affected version set to 2.4.3
- Subject changed from Memory Leak in cvThreshold to Memory Leak in imshow (on Windows)?
- Priority changed from Normal to Low
Updated by Vadim Pisarevsky about 12 years ago
- Category changed from imgproc, video to highgui-gui
Updated by Sebastian Krämer about 12 years ago
I'm thinking this might be a false positive memory leak message due to TBB library. I've experienced the error in Visual Studio's Debugger when I built OpenCV against TBB (also using HighGUI and parallel_for, I think).
Investigating the problem, I found a forum post that indicated (strongly) that there is some TBB magic going on that VS doesn't capture. Or it's TBB's fault, it's wasn't clear at the time. Searching the TBB forum [1] now indicates this might indeed be TBB's fault.
[1] http://software.intel.com/en-us/search/site/leak?f[0]=im_taxonomy_forums%3A36218&f[1]=im_taxonomy_forums%3A36940&retain-filters=1
Updated by Maksim Shabunin over 9 years ago
Issue has been transferred to GitHub: https://github.com/Itseez/opencv/issues/4386