diff options
author | Robert Griebl <robert.griebl@pelagicore.com> | 2015-03-23 13:28:49 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2015-03-25 14:10:22 +0000 |
commit | 2e9191f2a9a7dfb1be3f334c36e187255bd93842 (patch) | |
tree | 12cbb2aaa8aa5095a7f7b577b9c76a3042c80231 /tests/auto/quick/qquickstates | |
parent | 3f2eabc8d90c4ee535cb0a2500e033171e203537 (diff) |
Fixed a memory-leak when changing property bindings in states.
Bindings that were still stored in the revert-list when the state
was destructed were not deleted before. This could lead to considerable
memory leaks in big applications.
Change-Id: I73250f7d03a42c25ca729c18082125fd8f3c8989
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'tests/auto/quick/qquickstates')
-rw-r--r-- | tests/auto/quick/qquickstates/data/revertListMemoryLeak.qml | 16 | ||||
-rw-r--r-- | tests/auto/quick/qquickstates/tst_qquickstates.cpp | 25 |
2 files changed, 41 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickstates/data/revertListMemoryLeak.qml b/tests/auto/quick/qquickstates/data/revertListMemoryLeak.qml new file mode 100644 index 0000000000..b49487c895 --- /dev/null +++ b/tests/auto/quick/qquickstates/data/revertListMemoryLeak.qml @@ -0,0 +1,16 @@ +import QtQuick 2.0 + +Item { + id: rect + width: 40; + property real boundHeight: 42 + height: boundHeight; + + states: [ + State { + objectName: "testState" + name: "testState" + PropertyChanges { target: rect; height: 60; } + } + ] +} diff --git a/tests/auto/quick/qquickstates/tst_qquickstates.cpp b/tests/auto/quick/qquickstates/tst_qquickstates.cpp index 51fe9b4c96..6c42a7a0ee 100644 --- a/tests/auto/quick/qquickstates/tst_qquickstates.cpp +++ b/tests/auto/quick/qquickstates/tst_qquickstates.cpp @@ -141,6 +141,7 @@ private slots: void avoidFastForward(); void revertListBug(); void QTBUG_38492(); + void revertListMemoryLeak(); }; void tst_qquickstates::initTestCase() @@ -1634,6 +1635,30 @@ void tst_qquickstates::QTBUG_38492() delete item; } +void tst_qquickstates::revertListMemoryLeak() +{ + QWeakPointer<QQmlAbstractBinding> weakPtr; + { + QQmlEngine engine; + + QQmlComponent c(&engine, testFileUrl("revertListMemoryLeak.qml")); + QQuickItem *item = qobject_cast<QQuickItem *>(c.create()); + QVERIFY(item); + QQuickState *state = item->findChild<QQuickState*>("testState"); + QVERIFY(state); + + item->setState("testState"); + + QQmlAbstractBinding *binding = state->bindingInRevertList(item, "height"); + QVERIFY(binding); + weakPtr = QQmlAbstractBinding::getPointer(binding); + QVERIFY(!weakPtr.toStrongRef().isNull()); + + delete item; + } + QVERIFY(weakPtr.toStrongRef().isNull()); +} + QTEST_MAIN(tst_qquickstates) #include "tst_qquickstates.moc" |