Skip to content

Commit fa44b8a

Browse files
committed
fix: memory leak
Delay to create appLoaderItem, and it's lifecycle is managed by parentItem. DPalette of QQmlOpenMetaObjectType isn't release. Log: as title. pms: Task-368399
1 parent 7733998 commit fa44b8a

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/dquickwindow.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ DQuickWindowAttachedPrivate::DQuickWindowAttachedPrivate(QWindow *window, DQuick
6464
: DObjectPrivate(qq)
6565
, window(window)
6666
, wmWindowTypes(DWindowManagerHelper::UnknowWindowType)
67-
, appLoaderItem(new DQuickAppLoaderItem())
67+
, appLoaderItem(nullptr)
6868
{
6969
}
7070

@@ -482,6 +482,10 @@ QQmlComponent *DQuickWindowAttached::loadingOverlay() const
482482
DQuickAppLoaderItem *DQuickWindowAttached::appLoader() const
483483
{
484484
D_DC(DQuickWindowAttached);
485+
if (!d->appLoaderItem) {
486+
const_cast<DQuickWindowAttachedPrivate *>(d)->appLoaderItem =
487+
new DQuickAppLoaderItem(window()->contentItem());
488+
}
485489
return d->appLoaderItem;
486490
}
487491

@@ -494,7 +498,9 @@ void DQuickWindowAttached::setAppLoader(DQuickAppLoaderItem *item)
494498
// AppLoaderItem 会在窗口加载完毕后进行创建,因此
495499
// 在窗口创建初期,AppLoaderItem 需要指定一个默认
496500
// 值,防止 Qt 在运行时出现警告和报错
497-
d->appLoaderItem->deleteLater();
501+
if (d->appLoaderItem) {
502+
d->appLoaderItem->deleteLater();
503+
}
498504
d->appLoaderItem = item;
499505
Q_EMIT appLoaderChanged();
500506
}

src/private/dquickcontrolpalette.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,11 @@ class Q_DECL_HIDDEN CustomMetaObject : public QQmlOpenMetaObject
191191

192192
}
193193

194-
~CustomMetaObject()
194+
~CustomMetaObject() override
195195
{
196-
196+
if (auto item = type()) {
197+
item->release();
198+
}
197199
}
198200

199201
inline DQuickControlColorSelector *owner() const {

0 commit comments

Comments
 (0)