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

[Reg 6.5 -> 6.8] QJSEngine garbage collector no longer frees unreferenced functions

    XMLWordPrintable

Details

    Description

      Code

      #include <QCoreApplication>
      #include <QJSEngine>
      #include <QJSValue>
      #include <QTimer>
      
      int main(int argc, char *argv[])
      {
          QCoreApplication app(argc, argv);
          QJSEngine engine;
      
          int counter = 0;
      
          QTimer timer;
          QObject::connect(&timer, &QTimer::timeout, qApp, [&]
          {
              engine.evaluate(QStringLiteral("let obj = { f: function() { return %1 } }").arg(counter));
      
              counter++;
              if (counter % 200 == 0) // Collect garbage every 2s
                  engine.collectGarbage();
              else if (counter >= 1000) // Quit after 10s
                  app.quit();
          });
          timer.start(10);
      
          return app.exec();
      }
      
      

       

      Outcomes (heaptrack logs)
      (Qt 6.5.7) Each time engine.collectGarbage() is called, the consumed memory drops significantly:

       

      (Qt 6.8.1+) engine.collectGarbage() no longer has any effect; the consumed memory keeps increasing over time:

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              qtqmlteam Qt Qml Team User
              skoh-qt Sze Howe Koh
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes