Results 1 to 2 of 2

Thread: QDrag : memory allocation

  1. #1
    Join Date
    Jul 2008
    Location
    East Coast, USA
    Posts
    40
    Thanks
    6
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QDrag : memory allocation

    I'm using Instruments (on Mac) to track memory leaks in a QT app I wrote. I've gotten rid of the ones due to my code and am left with those it is not clear are really leaks and are from QT.

    1. QMessageBox - is it destroyed on close?
    2. QDrag - is it destroyed when the drag is complete?

    An example of the code that registers as a leak is:
    Qt Code:
    1. void about() {
    2. QMessageBox::information(this, "About X", "X is a program.\n")
    3. }
    To copy to clipboard, switch view to plain text mode 

    and,

    Qt Code:
    1. void PhotoMailer::mousePressEvent(QMouseEvent *event) {
    2. //http://doc.trolltech.com/4.2/dnd.html
    3. if (event->button() == Qt::LeftButton) {
    4. QDrag *drag = new QDrag((QWidget*)this);
    5. QMimeData *mimeData = new QMimeData;
    6. mimeData->setUrls(url);
    7. drag->setMimeData(mimeData);
    8. drag->start();
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

    My question is, should I worry - they are created with new and then 'lost', i.e. the calling function returns without telling anyone of the pointer, so I understand that a profiler will flag this as a leak, but will QT take care of them? Or have I missed a programming paradigm here.

    Thanks!
    -K

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

    Default Re: QDrag : memory allocation

    Quote Originally Posted by kghose View Post
    1. QMessageBox - is it destroyed on close?
    If used as a static call as in the code you presented then yes.
    2. QDrag - is it destroyed when the drag is complete?
    Yes.


    My question is, should I worry - they are created with new and then 'lost'
    The message box is not created with new, at least not explicitely. I'd say it's created on stack and goes out of scope when the function returns.

    , i.e. the calling function returns without telling anyone of the pointer, so I understand that a profiler will flag this as a leak, but will QT take care of them? Or have I missed a programming paradigm here.
    As far as I remember the docs say that Qt takes ownership of the drag object.

  3. The following 2 users say thank you to wysota for this useful post:

    D Cell (1st November 2010), kghose (15th August 2008)

Similar Threads

  1. Memory leak weirdness
    By Darhuuk in forum General Programming
    Replies: 10
    Last Post: 10th January 2008, 18:51
  2. Memory allocation failure and crash in QVector
    By ashatilo in forum Qt Programming
    Replies: 16
    Last Post: 20th October 2007, 23:27
  3. Memory Leak in my Application :-(
    By Svaths in forum Qt Programming
    Replies: 4
    Last Post: 27th July 2007, 19:42
  4. limit memory allocation
    By magland in forum General Programming
    Replies: 10
    Last Post: 23rd March 2007, 09:21
  5. vector memory allocation
    By TheKedge in forum General Programming
    Replies: 1
    Last Post: 23rd March 2006, 17:27

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.