Memory Leak in imshow (on Windows)? (Bug #2138)


Added by Robin Kaiser about 2 years ago. Updated over 1 year ago.


Status:Open Start date:2012-07-03
Priority:Low Due date:
Assignee:Vadim Pisarevsky % Done:

0%

Category:highgui-gui
Target version:3.0
Affected version:2.4.3 Operating System:
Difficulty: HW Platform:
Pull request:

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


2138.cpp (416 Bytes) Akos Marton, 2012-12-25 11:47 pm


Related issues (Add)


History

Updated by Kirill Kornyakov about 2 years ago

Could you please attach a sample code which shows the memory leak?

  • Assignee set to Kirill Kornyakov
  • Category set to imgproc, video

Updated by Robin Kaiser about 2 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 about 2 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.

  • Assignee changed from Kirill Kornyakov to Vadim Pisarevsky
  • Status changed from Open to Cancelled

Updated by Norman Link almost 2 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 almost 2 years ago

looks like several people observed this problem; need to investigate.

  • Target version set to 3.0
  • Status changed from Cancelled to Open

Updated by Akos Marton over 1 year 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;
}

Updated by Vadim Pisarevsky over 1 year 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

  • Subject changed from Memory Leak in cvThreshold to Memory Leak in imshow (on Windows)?
  • Priority changed from Normal to Low
  • Affected version set to 2.4.3

Updated by Vadim Pisarevsky over 1 year ago

  • Category changed from imgproc, video to highgui-gui

Updated by Sebastian Krämer over 1 year 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

Also available in: Atom PDF