Ask Your Question

kaga's profile - activity

2018-09-11 11:39:35 -0500 received badge  Notable Question (source)
2017-03-09 12:27:31 -0500 received badge  Popular Question (source)
2012-12-03 03:51:16 -0500 commented answer opencv imshow causing a memory leak (c++)

I'll do that. But can you tell me if the code is ok?

2012-12-03 03:49:39 -0500 received badge  Editor (source)
2012-12-03 02:46:04 -0500 commented answer opencv imshow causing a memory leak (c++)

Yes, of course I've called displayMyImage() method. But what should I do in order to fix it?

2012-12-03 02:44:12 -0500 received badge  Supporter (source)
2012-12-03 02:07:59 -0500 asked a question opencv imshow causing a memory leak (c++)

I wrote this method (it displays an image):

void ImageLoader::displayMyImage()
imshow("new_window1", m_image);

m_image is of Mat type.

I also use this destructor:


However, Valgrind found tons of memory leaks. It's caused by these two cv functions: namedWindow and imshow (because without calling the displayMyImage() there is no any leak). Is there a way to fix it?

Edit: Here is the example code:

//Constructors (here I use only the first):
ImageLoader::ImageLoader(int width, int height)
    : m_image(width, height, CV_8UC3)


ImageLoader::ImageLoader(const string& fileName)
    : m_image(imread(fileName))
  if (!
    cout << "Failed loading " << fileName << endl;

//main ( where I call displayImage() ):
int main12(int argc, char **argv)
    ImageLoader img1("Lenna.png");
    return 0;

I'm sure it's the displayImage() method to cause memory leaks. Because it appears only when I call it.