diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp index 346ca62a6f6..26e72018c5b 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper.cpp +++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp @@ -989,6 +989,10 @@ void QObjectWrapper::destroyObject(bool lastCall) // If the object is C++-owned, we still have to release the weak reference we have // to it. ddata->jsWrapper.clear(); + if (lastCall && ddata->propertyCache) { + ddata->propertyCache->release(); + ddata->propertyCache = nullptr; + } } } } diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp index 82bc3d0c59f..2642d10545a 100644 --- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp +++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp @@ -29,6 +29,7 @@ #include +#include #include #include #include @@ -73,6 +74,7 @@ private slots: void newQObject(); void newQObject_ownership(); void newQObject_deletedEngine(); + void newQObjectPropertyCache(); void newQMetaObject(); void exceptionInSlot(); void globalObjectProperties(); @@ -757,6 +759,19 @@ class TestQMetaObject : public QObject { int m_called; }; +void tst_QJSEngine::newQObjectPropertyCache() +{ + QScopedPointer obj(new QObject); + QQmlEngine::setObjectOwnership(obj.data(), QQmlEngine::CppOwnership); + + { + QJSEngine engine; + engine.newQObject(obj.data()); + QVERIFY(QQmlData::get(obj.data())->propertyCache); + } + QVERIFY(!QQmlData::get(obj.data())->propertyCache); +} + void tst_QJSEngine::newQMetaObject() { { QJSEngine engine;