Details
Description
When instantiating an object with Component.incubateObject and a null parent, the incubated object might be garbage collected before there is a chance to make a strong reference to it, as documented in https://doc.qt.io/qt-6/qml-qtqml-component.html#incubateObject-method
The patch in QTBUG-53111 does avoid the issue when the object is instantiated asynchronously, where in this case a reference to the object is kept until after the status is notified with statusChanged.
But if the object is instantiated right away, it will already be destroyed right after the incubateObject call.
This can be reproduced easily with the following code and QV4_MM_AGGRESSIVE_GC=1:
import QtQuick 2.0 Item { Component { id: comp Item { Component.onDestruction: print("DESTROY") Component.onCompleted: print("COMPLETED") } } Component.onCompleted: { var i = comp.incubateObject(null, {}, Qt.Asynchronous); print("incubate called"); i.onStatusChanged = () => { if (i.status == Component.Ready) { console.assert(i.object, "incubate failed: object is", i.object); } }; if (i.status == Component.Ready) console.assert(i.object, "incubate failed: object is", i.object); } }