From 953f0d44871b93a7a165e7026e48eaaadccf8d98 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Fri, 5 Jan 2024 19:06:05 +0100 Subject: QtQml: Clear stale compilation units more thoroughly There are various places where we can still hold references. Clean them up when asked to do so. Also, free unused types and caches outside the type loader mutex, and only once on engine shutdown. Change-Id: Iae77cd6f50ad847d29a7eae4ac5c7c1c2524065d Reviewed-by: Fabian Kosmale --- src/qml/qml/qqmlengine.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/qml/qml/qqmlengine.cpp') diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index a5f6d4d531..b01c592316 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -623,9 +623,19 @@ QQmlEngine::~QQmlEngine() void QQmlEngine::clearComponentCache() { Q_D(QQmlEngine); + + // Contexts can hold on to CUs but live on the JS heap. + // Use a non-incremental GC run to get rid of those. + QV4::MemoryManager *mm = handle()->memoryManager; + auto oldLimit = mm->gcStateMachine->timeLimit; + mm->setGCTimeLimit(-1); + mm->runGC(); + mm->gcStateMachine->timeLimit = std::move(oldLimit); + d->typeLoader.lock(); d->typeLoader.clearCache(); d->typeLoader.unlock(); + QQmlMetaType::freeUnusedTypesAndCaches(); } /*! -- cgit v1.2.3