Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-92912

Recursive QTimer:singleshot causes memory leak.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P2: Important P2: Important
    • None
    • 6.0.0, 6.0.3
    • Core: Event loop
    • None
    • Windows 7 x64 Ultimate
    • Windows

      I don't think this is expected behavior since a singleshot should be triggered and then deallocated.

      Steps to reproduce:

      1. Create a new Qt Widgets app.
      2. Create a function slot on MainWindow. Mine is called "executionLoop()"
      3. Call the function slot from the MainWindow constructor.
      4. Put the following code in the function:
      void MainWindow::executionLoop()
      {
          QTimer::singleShot(1, Qt::PreciseTimer, this, SLOT(executionLoop()));
      }

      The process will slowly but steadily use more RAM while never freeing it. executionLoop is called once from outside and only recursively after that, so only one timer should be active at a given time.

      Minimal test project is attached.

      After some more testing, the problem seems to persist up to around a timer of 400 milliseconds, though it's really, really slow. It seems to drop off at about 500 milliseconds.

      This also occurs with a recurring QTimer created and connected from outside the loop and an empty slot function.

        For Gerrit Dashboard: QTBUG-92912
        # Subject Branch Project Status CR V

            thiago Thiago Macieira
            bcrew1375 Benjamin Crew
            Votes:
            2 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:

                There is 1 open Gerrit change