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

Garbage collector cleans up js imports too early

    XMLWordPrintable

Details

    • All

    Description

      In the attached project that should compile and run successfully, the issue happens in logic.js:10 where answerToLife fails to return 42 because Constants is null. The rest of the project is boilerplate to make it compile and run and trigger the bug.

      Looking at logic.js:1 you see

      .import "constants.js" as Constants
      

      and it's not obvious why Constants would be null.
      The actual output is

      qml: TempScreen created
      qml: Answerer created
      qml: TempScreen destroyed
      qml: Answerer trying to get answer, but Constants is null so I get
      qrc:/logic.js:10: TypeError: Cannot read property 'answer' of null
      

      The expected output would for the last line to print

      The answer to life is 42
      

      instead.

      The apparent reason is that main.qml:13 destroys tempScreen which cleans up Constants.js prematurely, even though var logic in main.qml:5 still relies on it.

      Attachments

        1. CMakeLists.txt
          0.4 kB
        2. constants.js
          0.0 kB
        3. logic.js
          0.3 kB
        4. main.cpp
          0.2 kB
        5. main.qml
          0.4 kB
        6. qml.qrc
          0.2 kB
        7. temp.qml
          0.3 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qtqmlteam Qt Qml Team User
            toeger Toe Ger
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes