From c5085eb8905f1a3c070f866746110980e84be271 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 Pick-to: 5.15 5.12 Done-with: Maximilian Goldstein Change-Id: I01d74f7eea442f8ba240dd66a4cedd6316fbeec2 Reviewed-by: Fabian Kosmale Reviewed-by: Ulf Hermann --- src/quick/items/qquickloader.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/quick/items/qquickloader.cpp') diff --git a/src/quick/items/qquickloader.cpp b/src/quick/items/qquickloader.cpp index d5a822c26f..fb0253e092 100644 --- a/src/quick/items/qquickloader.cpp +++ b/src/quick/items/qquickloader.cpp @@ -412,6 +412,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