From 78a5add79497300802c2152b5bf561b6bef305f1 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 21 Dec 2017 11:03:53 -0600 Subject: Remove extra addref The code was previously updated to use QQmlRefPointer, so we shouldn't explicitly addref. This allows more components to be correctly trimmed when needed. Change-Id: I15a961cfc456eeab5c791c8a282cc7e2852912cb Reviewed-by: Lars Knoll --- .../qqmltypeloader/data/ComponentWithIncubator.qml | 9 +++++++++ tests/auto/qml/qqmltypeloader/data/trim_cache3.qml | 14 ++++++++++++++ .../auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp | 21 +++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 tests/auto/qml/qqmltypeloader/data/ComponentWithIncubator.qml create mode 100644 tests/auto/qml/qqmltypeloader/data/trim_cache3.qml (limited to 'tests') diff --git a/tests/auto/qml/qqmltypeloader/data/ComponentWithIncubator.qml b/tests/auto/qml/qqmltypeloader/data/ComponentWithIncubator.qml new file mode 100644 index 0000000000..b3610831df --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/data/ComponentWithIncubator.qml @@ -0,0 +1,9 @@ +import QtQuick 2.0 + +Item { + Repeater { + model: 3 + Item {} + } +} + diff --git a/tests/auto/qml/qqmltypeloader/data/trim_cache3.qml b/tests/auto/qml/qqmltypeloader/data/trim_cache3.qml new file mode 100644 index 0000000000..219c7d3bcb --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/data/trim_cache3.qml @@ -0,0 +1,14 @@ +import QtQuick 2.0 + +Item { + width: 400 + height: 400 + + property alias source: loader.source + + Loader { + id: loader + source: "ComponentWithIncubator.qml" + } +} + diff --git a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp index 5ab729042f..5a3d76e903 100644 --- a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp +++ b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp @@ -44,6 +44,7 @@ private slots: void loadComponentSynchronously(); void trimCache(); void trimCache2(); + void trimCache3(); void keepSingleton(); void keepRegistrations(); void intercept(); @@ -124,6 +125,26 @@ void tst_QQMLTypeLoader::trimCache2() QCOMPARE(loader.isTypeLoaded(testFileUrl("MyComponent2.qml")), false); } +// test trimming the cache of an item that contains sub-items created via incubation +void tst_QQMLTypeLoader::trimCache3() +{ + QScopedPointer window(new QQuickView()); + window->setSource(testFileUrl("trim_cache3.qml")); + QQmlTypeLoader &loader = QQmlEnginePrivate::get(window->engine())->typeLoader; + QCOMPARE(loader.isTypeLoaded(testFileUrl("ComponentWithIncubator.qml")), true); + + QQmlProperty::write(window->rootObject(), "source", QString()); + + // handle our deleteLater and cleanup + QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); + QCoreApplication::processEvents(); + window->engine()->collectGarbage(); + + window->engine()->trimComponentCache(); + + QCOMPARE(loader.isTypeLoaded(testFileUrl("ComponentWithIncubator.qml")), false); +} + static void checkSingleton(const QString &dataDirectory) { QQmlEngine engine; -- cgit v1.2.3