aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2020-10-19 16:07:54 +0200
committerMaximilian Goldstein <max.goldstein@qt.io>2020-10-21 13:33:34 +0200
commitc5085eb8905f1a3c070f866746110980e84be271 (patch)
tree96d2c369cbc2459bf4ebe582d566d7591015c277 /src
parent8ba6cf600e7c3037016a6861aa429326d5c9095b (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 Pick-to: 5.15 5.12 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>
Diffstat (limited to 'src')
-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 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;