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

QJSEngine leaks memory

    XMLWordPrintable

Details

    • Linux/X11
    • 5aad93503 (dev), e8b924bec (6.9), d29f95dfb (6.8), 15394c704 (dev), 3285f5c8e (6.9), 9375a1b49 (6.8)

    Description

      A coworker of mine discovered a memory leak in QJSEngine. Here is a simple test program:

      /*
       * Demonstrate a memory leak in QJSEngine.
       *
       * Build with:
       *    qmake -project -o TestQJSEngine.pro
       *    echo 'QT += qml' >> TestQJSEngine.pro
       *    qmake TestQJSEngine.pro
       *    make
       */
      
      #include <QCoreApplication>
      #include <QJSEngine>
      #include <QDebug>
      
      int main(int argc, char *argv[])
      {
          QCoreApplication app(argc, argv);
          QJSEngine interpreter;
          QJSValue result;
          for (int i = 0; i < 1e7; i++)
              result = interpreter.evaluate("2+2");
          qDebug() << "Result is: " << result.toNumber();
      }
      

      Running under Qt 6.6.3, this program has a memory consumption (as reported by ps -o rss) that is quite stable, at around 16 MiB. Under Qt 6.8.1, however, the same program grows in size linearly in time, reaching close to 15 GiB.

      Here is a graph showing the RSS memory size as a function of time during the whole execution. Mind the logarithmic scale!

      Edit: fixed the horizontal scale on the graph.

      Attachments

        Issue Links

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

          Activity

            People

              olivier.decanniere Olivier De Cannière
              edgar.bonet Edgar Bonet Orozco
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: