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

qmlRegisterType and qmlRegisterUncreatableType leads to kind of leak

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 5.12.9, 6.0.0
    • None
    • custom embedded device (qt5.12.9) followed by a ubuntu 20.10 to track down the issue (qt 5.12.9 and then 6.0.0 to check if already fixed)
    • Linux/X11, Linux/Yocto

    Description

      Hi,

      Tracking down why I got sometime a OOM killer in my app, I found that multiple calls to the same qmlRegisterType or qmlRegisterUncreatableType leads to the memory growing again and again. I had a loop every 10ms, that created an object by copy which has in it's constructor, a call to the qmlRegisterUncreatableType function. Commenting this line let the issue disappear.

      Workaround is to create a static boolean variable to init the qml type only once.

      The issue is NOT present with qRegisterMetaType. I didn't tried all function available.

      Issue is not visible with valgrind, so it's not some kind of dynamic allocation not freed.

      Minimal example code to reproduce in Qt6.0.0 :
      I created a minimal QtQuick Application - Empty and changed the main function.
      The example use quint8 as class to register but it fail with any other class.

      #include <QGuiApplication>
      #include <QQmlApplicationEngine>
      #include <QTimer>
      
      int main(int argc, char *argv[])
      {
          QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
      
          QGuiApplication app(argc, argv);
      
          QQmlApplicationEngine engine;
          const QUrl url(QStringLiteral("qrc:/main.qml"));
          QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                           &app, [url](QObject *obj, const QUrl &objUrl) {
              if (!obj && url == objUrl)
                  QCoreApplication::exit(-1);
          }, Qt::QueuedConnection);
          engine.load(url);
      
          QTimer timerTestLeak;
          QObject::connect(&timerTestLeak,&QTimer::timeout, [] () {
              qmlRegisterUncreatableType<quint8>("quint8", 1, 0, "quint8", "Error: only enums and function call from qml");
          });
          timerTestLeak.start(2);
      
      
          return app.exec();
      }
      

      Start the app, launch htop and look the RES column,
      then comment the qmlRegisterUncreatableType, and compare the RES column.

      We should not get a growing memory usage for a call to the exact same registered object.

      Attachments

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

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            aridet aridet
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes