opencv imshow causing a memory leak (c++)
I wrote this method (it displays an image):
void ImageLoader::displayMyImage()
{
namedWindow("new_window1");
imshow("new_window1", m_image);
waitKey(2);
}
m_image is of Mat type.
I also use this destructor:
ImageLoader::~ImageLoader()
{
m_image.release();
}
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 (!m_image.data)
{
cout << "Failed loading " << fileName << endl;
}
}
//main ( where I call displayImage()
):
):
int main12(int argc, char **argv)
{
ImageLoader img1("Lenna.png");
img1.displayImage();
return 0;
}
I'm sure it's the displayImage() method to cause memory leaks. Because it appears only when I call it.
Thanks!