Skip to content

Commit

Permalink
fix: memory leak
Browse files Browse the repository at this point in the history
Delay to create appLoaderItem, and it's lifecycle is managed by parentItem.
DPalette of QQmlOpenMetaObjectType  isn't release.

Log: as title.
pms: Task-368399
  • Loading branch information
18202781743 committed Nov 20, 2024
1 parent bd44af2 commit 3083f67
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/dquickwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ DQuickWindowAttachedPrivate::DQuickWindowAttachedPrivate(QWindow *window, DQuick
: DObjectPrivate(qq)
, window(window)
, wmWindowTypes(DWindowManagerHelper::UnknowWindowType)
, appLoaderItem(new DQuickAppLoaderItem())
, appLoaderItem(nullptr)
{
}

Expand Down Expand Up @@ -482,6 +482,10 @@ QQmlComponent *DQuickWindowAttached::loadingOverlay() const
DQuickAppLoaderItem *DQuickWindowAttached::appLoader() const
{
D_DC(DQuickWindowAttached);
if (!d->appLoaderItem) {
const_cast<DQuickWindowAttachedPrivate *>(d)->appLoaderItem =
new DQuickAppLoaderItem(window()->contentItem());
}
return d->appLoaderItem;
}

Expand All @@ -494,7 +498,9 @@ void DQuickWindowAttached::setAppLoader(DQuickAppLoaderItem *item)
// AppLoaderItem 会在窗口加载完毕后进行创建,因此
// 在窗口创建初期,AppLoaderItem 需要指定一个默认
// 值,防止 Qt 在运行时出现警告和报错
d->appLoaderItem->deleteLater();
if (d->appLoaderItem) {
d->appLoaderItem->deleteLater();
}
d->appLoaderItem = item;
Q_EMIT appLoaderChanged();
}
Expand Down
6 changes: 4 additions & 2 deletions src/private/dquickcontrolpalette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,11 @@ class Q_DECL_HIDDEN CustomMetaObject : public QQmlOpenMetaObject

}

~CustomMetaObject()
~CustomMetaObject() override
{

if (auto item = type()) {
item->release();
}
}

inline DQuickControlColorSelector *owner() const {
Expand Down

0 comments on commit 3083f67

Please sign in to comment.