aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2020-10-19 16:07:54 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2020-10-21 14:15:43 +0000
commit92513ee677f3f4576a875a9e3195b0007278dc5e (patch)
treeaa4e1f0b6525b4d3dfb266547d8b3c3f9c6826f8
parent5d46199e3ae2e9fbc26bc9b4abf25c3acde1f6dd (diff)
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 <max.goldstein@qt.io> Change-Id: I01d74f7eea442f8ba240dd66a4cedd6316fbeec2 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit c5085eb8905f1a3c070f866746110980e84be271) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/quick/items/qquickloader.cpp13
1 files changed, 13 insertions, 0 deletions
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;