PDA

View Full Version : QPixmap memory leak problem



budda
3rd April 2013, 23:06
Ok so I wrote an application that I call Image Grabber in Windows 7.
It goes and grabs some weather doppler picture every 15 minutes, and saves it with a name having a unique date/time string...
It works fine, so I added it to do 6 images every 15 minutes. But eventually it crashes because of a memory leak.

A few other descriptions.
-It gets the image by using the filedownloader class. (QUrl with a slot that executes after finished download)
-I am running it from the icon tray with 4 QIcon's that replace on a timer.
-It saves the images to the hard drive and also there is a QWidgetStack that has 6 divisions, with each one displaying the QPixmap in a QLabel.

my question is this memory problem to do the
QPixmaps themselves?
or possibly setting the QLabel QPixmap?
or even possibly the filedownloader class?
will QPixmapCache solve this?

for a work around, I could write another application that calls the original one once every 15 minutes and it closes after the last file saved, therefore insuring that there is no memory leak, but I shouldn't have to do that.

any help would be awesome.

wysota
3rd April 2013, 23:27
The problem is in your code.

budda
4th April 2013, 00:26
Certainly it is my code. The question is what would cache QPixmaps indefinitely? Just the process of creating the same 6 with a different QNetworkRequested URL's every 15 minutes. Or the QLabel->setPixmap() function calls, which are also every 15 minutes.....


#include <QtGui/QApplication>

QByteArray FileDownloader::downloadedData() const
{
return m_DownloadedData;
}


Added after 18 minutes:

I'm just saying this seems fairly straight foward. Find the Milleseconds till the next 15 min block, singleshot untill then, go get the pics, put them in the labels, save them in the corresponding directory, since the QNetworkRequests are asynchronous, do another singleshot of 1 minute later (while all 6 are downloading and then writing to disk) then recalculate the next singleshot for the next 15 minutes... repeat forever...

ChrisW67
4th April 2013, 00:36
There's no QPixmap related memory leak I can see in your code (I can see a bunch of unused pointers-to-QPixmap). I'd be looking elsewhere for the leak or other cause for the crash.

budda
4th April 2013, 00:45
in the header those unused pointers are commented out. I was trying to delete the Pixmap instances but wasn't working. I'll just write a second program that does all the timer stuff and just calls this program to do a one time save then close... just trying plug the holes that cron commands occasionally make by doing it on a home pc. AND I was just getting frustrated as it works, but somehow just keeps building memory... my main PC with 32GB of RAM can run for a long time, but I was trying to run it on a crappy old XP that I was leaving on indefinitley.... I did write and run this in Qt 4.6 I'll bump it up to my VM versions of 4.7 & 4.8 and see if that helps....

d_stranz
4th April 2013, 00:55
Geez, nobody told you about CODE tags, did they? When you want to paste code, either click "Go Advanced" and then the "#" that appears on the toolbar and paste your code between the tags, or insert the pair CODE and /CODE (enclosed in "[" and "]", like and ) by typing and paste between them. Trying to read the unformatted code you posted is nearly impossible.

It isn't obvious where the leak is, if there is one. From what I can read, those things you allocate dynamically are allocated only once, and everything else is done with local stack-based variables.

I would start by simplifying this code drastically until you can isolate the problem: Download from ONE site only, to ONE pixmap. Comment out sections of the code to nullify their effect, for example, download the data but don't set it to a label or save it to a file. If that doesn't leak, then add in the next step. If that doesn't leak, add another step, and so on, until something you add back in does result in a leak again.

budda
4th April 2013, 00:59
well snap, there used to be code tag icon now there's not... I forgot... and yes isolate variables, I understand...

d_stranz
4th April 2013, 01:02
there used to be code tag icon now there's not

Yeah, I know. At some point it disappeared from the simple menu and got moved to the advanced menu. You would think that a button on the simple menu to insert CODE tags would be more useful than a button to "Insert Video".

budda
4th April 2013, 01:11
well again thanks, I've been tweaking it for a week trying to fix the build up before I posted. Trying to solve stuff on my own as to not sound retarded. I've had an easier time with Phonon than solving this one!!!!!

budda
4th April 2013, 03:23
OMG the animated tray icon was on a QTimer of 10 milliseconds with an integer being increased by 1 in the void MainWindow::timerEvent(QTimerEvent *e)
I never gave it a maximum cap and then set it back to zero... the memory leak was an int going larger than the ~32767.... duh....

wysota
4th April 2013, 06:49
You have memory leaks regarding the QDir instances you create on the heap.

d_stranz
4th April 2013, 20:02
the memory leak was an int going larger than the ~32767

An "int" is usually a 32-bit quantity, so the max is a little bit larger than 32767. A signed short would max out at that.

Your original code has been deleted, so I can't comment on Wysota's QDir observation. I thought I had checked the first time I read through it and decided that those were one-time calls. Probably missed something.

budda
13th April 2013, 22:19
I figured it out, after isolating parts, I had to delete the instances of the FileDownload class and that fixed it. It's been running for 9 days without a hiccup with only 18,xxx of RAM useage...