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

Backport whatever changes JS engine memory management behavior to 6.2 and 5.15

    XMLWordPrintable

Details

    Description

      Reproducer attached. Run it with Qt 5.15 or 6.2 and it crashes at about (in my case) 1600th update to "MyObject*" which is a QObject* defined on C++ side and returned to QML side as the "text" property of Text.

      Uncomment 4 "QQmlEngine::setObjectOwnership(data, QQmlEngine::CppOwnership);" lines in myObjectModel.cpp, and problem is gone.

      So what is happening is that (I think) MyObject* is returned to QML side directly from a C++ function call, then its ownership is transferred to QML engine. And QML engine garbage-collects it by mistake (so giving ownership back to C++ avoid it from happening). But at this point, MyObject* itself is not destroyed. Actually I am not 100% what is going on by:
      Memory Management in the JavaScript Engine | Qt QML 6.6.1
      What I suppose is that the "wrapper" is gc()'ed, so does the pointer to C++ heap where MyObject* locates. But MyObject* is still alive.

      But anyway, run the sample with Qt6.6 then no error happens even without setting ownership. So something must be backported. but I don't know what yet.

      Attachments

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

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes