-
Bug
-
Resolution: Fixed
-
P1: Critical
-
5.14.2, 5.15.0
When creating an object with Component.createObject, then connecting to a signal on it and destroying it, qml will leak QQmlContext objects over time. Here's a minimal example:
import QtQuick 2.11
Item {
id: root
signal outer
Component {
id: comp
Item {
signal inner
}
}
Timer{
repeat: true
interval: 50
running: true
onTriggered: {
let obj = comp.createObject(root);
root.outer.connect(obj.inner)
//WORKAROUND
//root.outer.disconnect(obj.inner)
obj.destroy()
gc()
}
}
//"Objects are not destroyed
//the instant destroy() is called, but are cleaned up sometime between the end
//of that script block and the next frame (unless you specified a non-zero
//delay)."
/*Component.onCompleted: {
while (true) {
let obj = comp.createObject(root);
root.outer.connect(obj.inner)
obj.destroy()
gc()
}
}*/
}
The signal to signal connection prevents the object from cleanup. Either disconnect should happen automatically or the documentation should mention, that disconnect is needed.
- depends on
-
QTBUG-88248 QObject orphaned connections soft-leak
-
- Closed
-
- relates to
-
QTBUG-88587 QQuickWidget object stay in QML Engine cache after deletion
-
- Closed
-
| For Gerrit Dashboard: QTBUG-86368 | ||||||
|---|---|---|---|---|---|---|
| # | Subject | Branch | Project | Status | CR | V |
| 330192,3 | Add new special QObjectPrivate::{connect, disconnect} for QML | dev | qt/qtbase | Status: MERGED | +2 | 0 |
| 330298,9 | Use new QObjectPrivate connection mechanism in dynamic connections | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |
| 330484,2 | Add new special QObjectPrivate::{connect, disconnect} for QML | 6.0 | qt/qtbase | Status: MERGED | +2 | 0 |
| 330587,3 | Add new special QObjectPrivate::{connect, disconnect} for QML | tqtc/lts-5.15 | qt/tqtc-qtbase | Status: MERGED | +2 | 0 |
| 330890,1 | Use new QObjectPrivate connection mechanism in dynamic connections | 6.0 | qt/qtdeclarative | Status: ABANDONED | -1 | 0 |
| 330891,2 | Use new QObjectPrivate connection mechanism in dynamic connections | tqtc/lts-5.15 | qt/tqtc-qtdeclarative | Status: ABANDONED | -1 | 0 |