QImage.scanLine pointer memory leak
Hi,
I have a piece of code to display images one after the other. I noticed a memory leak when I "play" 100 images or so.
Here is the code
Code:
uint * scanLine;
for (int i = 0; i < height; i++)
{
scanLine = (uint *) image.scanLine(i);
for (int j = 0; j < width; j++)
{
pixel = 0xff - c[i * width + j];
scanLine[j] =qRgb(pixel, pixel, pixel); //memory leak here
}
}
delete [] c;
The image is displayed correctly but I cannot figure out what I am doing wrong here and why there is a memory leak.
height and width are 3000. c[] is a table of char with the image values. The image is a greyscale.
Can anyone help me solving this memory leak?
Cheers,
Arnaud
Re: QImage.scanLine pointer memory leak
The image should delete all of the memory it has allocated.
Which leak checker did you use that says that the QImage leaks its memory?
Cheers,
_
Re: QImage.scanLine pointer memory leak
Hi,
I am developing on linux and I use the system monitor. it is pretty clear. Each time I run the above code in loop to display successively 100 images the is a leak of ~3.5GB. If I run the loop again an additional 3.5GB is leaked. When I shutdown the app all memory is freed.
Commenting out scanLine[j] =qRgb(pixel, pixel, pixel); solve the problem. I'll try to reproduce with simple test code and try to find my error.
Cheers,
Rno
Re: QImage.scanLine pointer memory leak
And the QImage itself goes out of scope after it has been used?
Cheers,
_
Re: QImage.scanLine pointer memory leak [SOLVED]
Hi,
Yes the image is out of scope but you guided me toward the solution by simplifying the code.
The problem is not the code above but below (I should have included it)
Code:
m_scene
->addPixmap
(QPixmap::fromImage(GetImageFromDetector
(ExpData.
FileAndPath)))
I am adding a Pixmap to Qgraphicscene rather than replacing.
Code:
m_scene->clear();
m_scene
->addPixmap
(QPixmap::fromImage(GetImageFromDetector
(ExpData.
FileAndPath)));
solved the problem.
Thanks a lot for making me think.
Rno
Re: QImage.scanLine pointer memory leak [SOLVED]
Quote:
Thanks a lot for making me think.
Thinking is one of those things we should all do from time to time. It would hurt so much less if we used our heads for thinking rather than banging them on the wall.