From 92513ee677f3f4576a875a9e3195b0007278dc5e Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Mon, 19 Oct 2020 16:07:54 +0200 Subject: qquickloader: Free memory of loaded components after source change Since we cannot be sure when the event loop that would usually handle deferred deletions will run the next time we have to delete these components immediately otherwise we might run out of memory. Fixes: QTBUG-86676 Done-with: Maximilian Goldstein Change-Id: I01d74f7eea442f8ba240dd66a4cedd6316fbeec2 Reviewed-by: Fabian Kosmale Reviewed-by: Ulf Hermann (cherry picked from commit c5085eb8905f1a3c070f866746110980e84be271) Reviewed-by: Qt Cherry-pick Bot --- src/quick/items/qquickloader.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/quick/items/qquickloader.cpp b/src/quick/items/qquickloader.cpp index d0e29c204e..970e808854 100644 --- a/src/quick/items/qquickloader.cpp +++ b/src/quick/items/qquickloader.cpp @@ -411,6 +411,19 @@ void QQuickLoader::setSource(const QUrl &url) void QQuickLoader::setSource(const QUrl &url, bool needsClear) { Q_D(QQuickLoader); + + // The source has been changed at this point, and we assume that (after + // notifying potential listeners with sourceChanged) that it is now + // safe to actually delete the old component. We have to do this here + // in case the component referenced expensive resources (like uncached + // images), as it might take too long until we return to the event loop. + // We need to explicitly pass QEvent::DeferredDelete to sendPostedEvents, + // else the allowDeferredDelete check in qcoreapplication.cpp will not + // allow the event to pass. This will not affect anything deleted by this + // call, only the previous one. This has to be done as otherwise there + // might be signal handlers that are still in progress. + QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); + if (d->source == url) return; -- cgit v1.2.3