Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.3.0
-
None
-
714d9d95484907378b46292df7aec0832f557f1d (qtdeclarative)
Description
This Qml code continuously creates objects with Component.createObject() and destroys them immediately afterwards:
import QtQuick 2.2 import QtQuick.Window 2.0 Window { title: qsTr("Component.createObject Leak Test") width: 640 height: 480 property int createdCount; property int destroyedCount; Text { text: "Created: " + createdCount + "\nDestroyed: " + destroyedCount } Timer { id: timer interval: 10 repeat: true running: true onTriggered: { for (var i = 0; i < 40; i++) { var obj = factory.createObject(); obj.destroy(); } } } Component { id: factory Item { Component.onCompleted: createdCount++ Component.onDestruction: destroyedCount++ } } }
Memory use should stay constant, but instead it grows continuously. Valgrind's leak check shows this leak:
==26587== 2,341,380 (849,000 direct, 1,492,380 indirect) bytes in 7,075 blocks are definitely lost in loss record 4,508 of 4,508 ==26587== at 0x402A77B: operator new(unsigned int) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so) ==26587== by 0x45F4818: QQmlComponentPrivate::beginCreate(QQmlContextData*) (in /home/schuspe/Qt5.3.0/5.3/gcc/lib/libQt5Qml.so.5.3.0) ==26587== by 0x45F4CA9: QQmlComponent::beginCreate(QQmlContext*) (in /home/schuspe/Qt5.3.0/5.3/gcc/lib/libQt5Qml.so.5.3.0) ==26587== by 0x45F304B: QQmlComponent::createObject(QQmlV4Function*) (in /home/schuspe/Qt5.3.0/5.3/gcc/lib/libQt5Qml.so.5.3.0) ==26587== by 0x46DF128: ??? (in /home/schuspe/Qt5.3.0/5.3/gcc/lib/libQt5Qml.so.5.3.0) ==26587== by 0xBEDA475B: ???
There's only one "new" in QQmlComponentPrivate::beginCreate, at qtdeclarative/src/qml/qml/qqmlcomponent.cpp:883 in the Qt 5.3.0 release:
state.creator = new QQmlObjectCreator(context, cc, creationContext);
It appears that a new state.creator is being created every time createObject() is called, regardless of whether one had already been created.
Attachments
For Gerrit Dashboard: QTBUG-39742 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
88028,2 | Fix memory leak in QQmlComponent::createObject | 5.3 | qt/qtdeclarative | Status: MERGED | +2 | 0 |