Results 1 to 13 of 13

Thread: QPixmap memory leak problem

  1. #1
    Join Date
    Mar 2010
    Posts
    86
    Thanks
    11
    Thanked 7 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default QPixmap memory leak problem

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPixmap memory leak problem

    The problem is in your code.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2010
    Posts
    86
    Thanks
    11
    Thanked 7 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPixmap memory leak problem

    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.....

    Qt Code:
    1. #include <QtGui/QApplication>
    2.  
    3. QByteArray FileDownloader::downloadedData() const
    4. {
    5. return m_DownloadedData;
    6. }
    To copy to clipboard, switch view to plain text mode 


    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...
    Last edited by budda; 4th April 2013 at 01:00.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QPixmap memory leak problem

    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.
    Last edited by ChrisW67; 4th April 2013 at 00:41.
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

  5. The following user says thank you to ChrisW67 for this useful post:

    budda (4th April 2013)

  6. #5
    Join Date
    Mar 2010
    Posts
    86
    Thanks
    11
    Thanked 7 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPixmap memory leak problem

    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....

  7. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,316
    Thanks
    315
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QPixmap memory leak problem

    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 [FOO] and [/FOO]) 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.

  8. The following user says thank you to d_stranz for this useful post:

    budda (4th April 2013)

  9. #7
    Join Date
    Mar 2010
    Posts
    86
    Thanks
    11
    Thanked 7 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPixmap memory leak problem

    well snap, there used to be code tag icon now there's not... I forgot... and yes isolate variables, I understand...

  10. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,316
    Thanks
    315
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QPixmap memory leak problem

    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".

  11. #9
    Join Date
    Mar 2010
    Posts
    86
    Thanks
    11
    Thanked 7 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPixmap memory leak problem

    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!!!!!

  12. #10
    Join Date
    Mar 2010
    Posts
    86
    Thanks
    11
    Thanked 7 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPixmap memory leak problem

    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....

  13. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPixmap memory leak problem

    You have memory leaks regarding the QDir instances you create on the heap.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. #12
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,316
    Thanks
    315
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QPixmap memory leak problem

    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.

  15. #13
    Join Date
    Mar 2010
    Posts
    86
    Thanks
    11
    Thanked 7 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QPixmap memory leak problem

    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...

Similar Threads

  1. Replies: 1
    Last Post: 16th December 2009, 07:01
  2. Qt dll + memory leak
    By Fastman in forum Qt Programming
    Replies: 3
    Last Post: 2nd August 2009, 13:28
  3. QPixmap: X11 "memory leak" due to shared pixmap data?
    By chezifresh in forum Qt Programming
    Replies: 0
    Last Post: 21st April 2009, 19:53
  4. QPixMap and Memory leak
    By Krish_ng in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2007, 14:18
  5. Memory leak
    By vvbkumar in forum General Programming
    Replies: 4
    Last Post: 2nd September 2006, 15:31

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.