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

QQmlEngine and QJSEngine don't free memory when list of objects is returned from C++ code invoked bu JS code

    XMLWordPrintable

Details

    • All

    Description

      We have an application that we want to make scriptable. To achieve this we use QQmlEngine or QJSEngine (they both behave the same way). To make scripting easier we want to return objects to script and be able to call object methods. We create a Q_INVOKABLE which returns a QObject-inherited wrapper over an actual object and we want this wrapper to be deleted after finisning script (an actual data is not deleted). 

      Returned object has JavaScript ownership by default (according to the documenatation and all tests I've done) and after we finish script and delete underlying engine, it is deleted properly.

      But if we return QList <QObject *> the very same way, these objects are not deleted which causes a memory leak.

       

      A minimal reproducable example is attached, you can also find it on github

      https://github.com/BeardedBeaver/QmlPassObjectTest

       

      To summarize - a single QObject pointer returned to QQmlEngine from C++ is deleted properly, while QList <QObject *> returned the very same way with the very same settings is not deleted which causes a memory leak.

      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
            beardedbeaver Dmitriy Linev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes