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

[Reg 6.5.9 -> 6.8.4] Unreferenced objects with JavaScriptOwnership are no longer destroyed

XMLWordPrintable

    • b1c48db75 (dev), 6efdecd36 (6.10), 28cb8f65b (6.9)

      See the attached example. CppObj is a QML_ELEMENT while CppBridge is a QML_SINGLETON.

      It creates 3 CppObjs with JavaScriptOwnership and no parent:

      Identifier Comment
      -1 Instantiated declaratively in QML
      0 Instantiated from C++, not stored
      1 Instantiated from C++, stored in QML property

       

      Code

      import QtQuick
      import QtQuick.Controls.Basic
      import JSOwnershipStudy
      
      Window {
          width: 400
          height: 300
          visible: true
      
          property CppObj objFromCpp: CppBridge.singleObj(1) // identifier == 1
          CppObj { id: objFromQml } // identifier == -1
      
          Component.onCompleted: {
              const orphanedObj = CppBridge.singleObj(0) // identifier == 0
          }
      
          Button {
              text: "Collect Garbage"
              onClicked: gc()
          }
      }
      

       

      Steps to reproduce

      1. Run the attached example
      2. Click the "Collect Garbage" button
      3. Close the window to quit

       

      Outcomes

      • (All versions) CppObj IDs -1 and 1 are destroyed upon quitting (Expected)
      • (Qt 6.5) CppObj ID 0 is destroyed by the garbage collector (Expected)
      • (Qt 6.8+) CppObj ID 0 is never destroyed (Not Expected)

       
      Setting QV4_GC_TIMELIMIT=0 and QV4_MM_AGGRESSIVE_GC=1 does not help.

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

            ulherman Ulf Hermann
            skoh-qt Sze Howe Koh
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: