Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt5 QFileDialog is leaking memory?
Forum Updated to NodeBB v4.3 + New Features

Qt5 QFileDialog is leaking memory?

Scheduled Pinned Locked Moved General and Desktop
13 Posts 3 Posters 6.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    utcenter
    wrote on last edited by
    #1

    All there is - a QString local and a QFileDialog leaks over 1 MB of memory each time it is executed, regardless if it is parented to the Widget or 0.

    @void Widget::fileToString()
    {
    QString fileName = QFileDialog::getOpenFileName(this, "Open Text File", "", "Text Files (*.txt)");
    }@

    A bug? Or am I "missing" something? Can anyone verify that?

    *Note - I didn't use leak detection software, just watching it in the task manager, even opening the dialog without selecting anything leaks some kb, but selecting a file leaks well over 1 mb and it builds up...

    1 Reply Last reply
    0
    • U Offline
      U Offline
      utcenter
      wrote on last edited by
      #2

      No one to confirm or refute that? Each opening of a dialog leaking over a MB of memory is a pretty significant bug...

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DerManu
        wrote on last edited by
        #3

        Can't confim. This is my code:
        @void MainWindow::on_pushButton_clicked()
        {
        while (true)
        {
        QString fileName = QFileDialog::getOpenFileName(this, "Open Text File", "", "Text Files (*.txt)");
        setWindowTitle(fileName);
        }
        }@
        This is my system: Qt 4.8.3, GCC 4.7.2, GNU/Linux
        This is my memory development (in MiB) for 10 dialog iterations per line:
        Virtual -- Resident -- Shared
        69.5 -- 19.0 -- 15.5
        206 -- 23.4 -- 18.2
        206 -- 23.6 -- 18.4
        206 -- 23.6 -- 18.4
        206 -- 23.6 -- 18.4
        206 -- 23.6 -- 18.4
        And it has reached a steady state at the third line. Measured with htop. How did you measure and what's your system? Did you check valgrind?

        1 Reply Last reply
        0
        • U Offline
          U Offline
          utcenter
          wrote on last edited by
          #4

          No, I don't have linux. Monday I can check with intel's... inspector or whatever it was called.

          My build is Qt5.0 from git with MSVC2012 x64

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DerManu
            wrote on last edited by
            #5

            Hm that's a different system in every possible aspect, so it probably won't make any sense to compare. Maybe someone with a more similar system can do tests.

            1 Reply Last reply
            0
            • B Offline
              B Offline
              brainTech
              wrote on last edited by
              #6

              Valgrind is a great tool to check memory leak. It is available under http://valgrind.org/.

              This memory leak is not only occur in qt5 but also occurs in versions < qt4.8. One obvious solution to this leak is to user deleteLater on QFileDialog.

              Cheers,

              1 Reply Last reply
              0
              • D Offline
                D Offline
                DerManu
                wrote on last edited by
                #7

                [quote author="brainTech" date="1357580397"]This memory leak is not only occur in qt5 but also occurs in versions < qt4.8.[/quote]
                What's your source for that? How come I didn't observe it? Is it x64/Win only?

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  brainTech
                  wrote on last edited by
                  #8

                  I have tested it on MacOS 10.7.4 with Qt 4.8.1. While opening QFileDialog several times, memory increases to 200 Mb even 300 MB.

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    DerManu
                    wrote on last edited by
                    #9

                    [quote author="brainTech" date="1357581223"]I have tested it on MacOS 10.7.4 with Qt 4.8.1. While opening QFileDialog several times, memory increases to 200 Mb even 300 MB.[/quote]

                    Please provide measurements like I did above. To determine whether there is a problem requires more empiric rigour than "open several times". Take my code above and note Virtual, Resident and Shared memory usage of the process at every 10-dialog-mark. Do that until you reach a clear linear trend (either constant (good) or rising (bad)), at least 100 dialog open/close iterations. Maybe all you observed was some standard UI libraries being loaded into virtual memory?

                    //EDIT: I'm not trying to be harsh or discredit you, I just want clear facts when it comes to serious stuff like memory leaks in such an important part of the library.

                    1 Reply Last reply
                    0
                    • B Offline
                      B Offline
                      brainTech
                      wrote on last edited by
                      #10

                      I'm now home but i'll post the results of valgrind tomorrow.

                      1 Reply Last reply
                      0
                      • U Offline
                        U Offline
                        utcenter
                        wrote on last edited by
                        #11

                        Tested with intel inspector today, but the results are hardly useful, got so many leak detections from numerous locations that I hardly know what to make out of it. Fact is, even file selection boosts the memory footprint by 1+ mb.

                        1 Reply Last reply
                        0
                        • B Offline
                          B Offline
                          brainTech
                          wrote on last edited by
                          #12

                          Hi DerManu,
                          I forgot to mention that memory leak does not occur when you use static member function of QFileDialog. When you try to use QmessageBox *messageBox = new QMessageBox(); then leak occur. With this, 2-3 MB is increasing.
                          Real Memory (MB)
                          125
                          128
                          131
                          135
                          139
                          144
                          .
                          .
                          245

                          It keeps on increasing. I have put the measurements from Activity Monitor of MacOS.

                          I am also new to Qt/QtScript. I was having these issues in the last 2 weeks. I solved this by exec and deleteLater. Is this the right solution? With this solution, memory first increases and then becomes stable at some point but it never comes back to the point from where it started. Can you please put your thoughts on this? Is the behaviour of memory is right?

                          Regards,

                          1 Reply Last reply
                          0
                          • U Offline
                            U Offline
                            utcenter
                            wrote on last edited by
                            #13

                            Well, I get the memory consumption increase exactly with the static method. And there is nothing to call deleteLater on unfortunately.

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved