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

Generated code does not track objects on JavaScript stack

XMLWordPrintable

    • 2d016a265 (dev), 2356043fc (6.10), e1bd1baee (6.9)

      Consider:

      #ifndef COLLECTOR_H
      #define COLLECTOR_H
      
      #include <QtCore/qobject.h>
      #include <QtQmlIntegration/qqmlintegration.h>
      #include <QtQml/qjsengine.h>
      
      class Collector : public QObject
      {
          Q_OBJECT
          QML_ELEMENT
      
      public:
          Q_INVOKABLE void gc()
          {
              qjsEngine(this)->collectGarbage();
          }
      };
      
      #endif // COLLECTOR_H
      
      pragma Strict
      import QtQml
      
      Collector {
          id: self
          property Component c: QtObject { objectName: "dynamic" }
          property QtObject o: c.createObject()
      
          Component.onCompleted: {
              var oo = o
              o = null
              self.gc()
              o = oo
          }
      }
      
      #include <QGuiApplication>
      #include <QQmlApplicationEngine>
      
      int main(int argc, char *argv[])
      {
          QGuiApplication app(argc, argv);
      
          QQmlApplicationEngine engine;
          QObject::connect(
              &engine,
              &QQmlApplicationEngine::objectCreated,
              &app,
              [](QObject *o) {
                  qDebug() << o->property("o");
                  QCoreApplication::exit(0);
              },
              Qt::QueuedConnection);
          engine.loadFromModule("deletedobjects", "Main");
      
          return app.exec();
      }
      

      This will output QVariant(QObject*, 0x0) when run with disk cache and QVariant(QObject*, 0x611000007700) when run with QML_DISABLE_DISK_CACHE=1

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

            ulherman Ulf Hermann
            ulherman Ulf Hermann
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                There is 1 open Gerrit change