memory leak when destroy qquickwidget
-
I am using Qt 5.12/Qt5.11, my widget inheirt from qwidiget and embedded an quickwidget in my widget, there is significant memory leak when destroy QuickWidget .
Below is my widget class:class TestPage : public QWidget { Q_OBJECT public: explicit TestPage(QWidget *parent = nullptr); ~TestPage(); private: QQuickWidget *qquickWidget; QStackedLayout *l; signals: public slots: }; TestPage::TestPage(QWidget *parent) : QWidget(parent) { qquickWidget = nullptr; qquickWidget = new QQuickWidget(); qquickWidget->setSource(QUrl("qrc:/test.qml")); l = new QStackedLayout(); l->addWidget(qquickWidget); this->setLayout(l); } TestPage::~TestPage() { qDebug() << "destroy TestPage..."; if (qquickWidget) { //qquickWidget->engine()->clearComponentCache(); delete qquickWidget; qquickWidget = nullptr; } if (l) { delete l; l = nullptr; } }
code snip for test,
TestPage *testPage = new TestPage(); testPage->show(); testPage->close(); testPage->deleteLater();
We notice that memory increase 8M when 500 times new and destroy testPage .
I create a minimal example project on github:
https://github.com/tony-yuan-w/test_qquickwidget -
I am using Qt 5.12/Qt5.11, my widget inheirt from qwidiget and embedded an quickwidget in my widget, there is significant memory leak when destroy QuickWidget .
Below is my widget class:class TestPage : public QWidget { Q_OBJECT public: explicit TestPage(QWidget *parent = nullptr); ~TestPage(); private: QQuickWidget *qquickWidget; QStackedLayout *l; signals: public slots: }; TestPage::TestPage(QWidget *parent) : QWidget(parent) { qquickWidget = nullptr; qquickWidget = new QQuickWidget(); qquickWidget->setSource(QUrl("qrc:/test.qml")); l = new QStackedLayout(); l->addWidget(qquickWidget); this->setLayout(l); } TestPage::~TestPage() { qDebug() << "destroy TestPage..."; if (qquickWidget) { //qquickWidget->engine()->clearComponentCache(); delete qquickWidget; qquickWidget = nullptr; } if (l) { delete l; l = nullptr; } }
code snip for test,
TestPage *testPage = new TestPage(); testPage->show(); testPage->close(); testPage->deleteLater();
We notice that memory increase 8M when 500 times new and destroy testPage .
I create a minimal example project on github:
https://github.com/tony-yuan-w/test_qquickwidget@tony_yuan don't call directly
delete
on QObject/QWidget based classes.
Either give them -in this case - TestPage as parent and let qt internals handle the cleanup or calldeleteLater()
on them -
thanks for your reply, even I set parent for QQuickWidget and destroy them with deleteLater, there is still significant memory leak. The size of memory leak relate to the qml size.
While there is no memory leak if i use qquickview to load QML and also embedded into a qwidget.
TestPage::TestPage(QWidget *parent) : QWidget(parent) { quickview = nullptr; quickview = new QQuickView(); QWidget *container = QWidget::createWindowContainer(quickview, this); container->setMinimumSize(400, 400); container->setMaximumSize(400, 400); quickview->setSource(QUrl("qrc:/test.qml")); //embedded qquickview to qwidget l = new QStackedLayout(this); l->addWidget(container); this->setLayout(l); }
May be employee from QT can explain this issue. or only Qt5.12/Qt5.11 have this issue, i will try to install Qt5.15 later.
-
thanks for your reply, even I set parent for QQuickWidget and destroy them with deleteLater, there is still significant memory leak. The size of memory leak relate to the qml size.
While there is no memory leak if i use qquickview to load QML and also embedded into a qwidget.
TestPage::TestPage(QWidget *parent) : QWidget(parent) { quickview = nullptr; quickview = new QQuickView(); QWidget *container = QWidget::createWindowContainer(quickview, this); container->setMinimumSize(400, 400); container->setMaximumSize(400, 400); quickview->setSource(QUrl("qrc:/test.qml")); //embedded qquickview to qwidget l = new QStackedLayout(this); l->addWidget(container); this->setLayout(l); }
May be employee from QT can explain this issue. or only Qt5.12/Qt5.11 have this issue, i will try to install Qt5.15 later.
@tony_yuan said in memory leak when destroy qquickwidget:
May be employee from QT can explain this issue
maybe, but they usually do not frequent this forum, this is a mainly user based forum :(
i will try to install Qt5.15 later
try it, if it's still there and you actually have a minimal example project, show it to us, so we can also test it.
And that are then also ideal conditions for a bug report over at https://bugreports.qt.io/ :D