The QML engine appears to have a bug in object lifetime management. According to the documentation, an object will not be collected if it either has a parent or is referenced by the JS engine.
Yet in the following example, objects are deleted while still matching those two requirements. Objects are properly parented and referenced by JS code when they get deleted:
The example is a trivial object tree builder, with the left button adding a leaf to the node and the right button collapsing the node. All it takes to reproduce the bug is to create a node with depth of 3 and then collapse and expand the root node, upon which the console output shows:
This is just one of the several cases I experienced arbitrary object deletions, such happen to both objects, returned from C++ and objects, created entirely in QML. In this particular case the deletion seems to be connected to where createObject() is being called - if instead in the UI the objects is created in a function in main.qml, which is called in the UI then the deletion does not take place. However, I wasn't able to pinpoint any such dependencies in the other cases of arbitrary object deletion.
|For Gerrit Dashboard: QTBUG-50319|
|228466,4||Fix JS ownership of model and delegate properties in QtQuick item views||dev||qt/qtdeclarative||Status: MERGED||+2||0|