[Interest] Memory leak in grabToImage?

Marc Van Daele marc.van.daele90 at gmail.com
Mon Aug 10 10:32:06 CEST 2020


Hello,

The following example application has a memory leak when using 5.12.6 on
Linux (when monitoring with htop, the memory of the process increases
systematically).
Is this a programming error or a bug in Qt?

Looking forward to your input,

Marc

In QML, I take a screenshot every second

    Timer {

        id: memoryMonitor

        interval: 1*1000

        repeat: true

        onTriggered: utils.takeScreenshot()

    }

    Component.onCompleted: memoryMonitor.start()


In main.cpp, I register my Utils class as a context property

    Utils utils((QQuickWindow*)(app.allWindows()[0]));

    engine.rootContext()->setContextProperty("utils", &utils);

My Utils class looks like

class Utils : public QObject

{

    Q_OBJECT

public:

    explicit Utils(QQuickWindow* rootView, QObject *parent = nullptr);

    Q_INVOKABLE void takeScreenshot();

signals:

public slots:

private:

    QQuickWindow* m_rootView;

};

Utils::Utils(QQuickWindow* rootView, QObject *parent) : QObject(parent)

{

    m_rootView = rootView;

}


void Utils::takeScreenshot()

{

    QQuickItem *item = m_rootView->contentItem();

    QSharedPointer<QQuickItemGrabResult> grab = item->grabToImage();

    if(grab.get() != nullptr) {

        connect(grab.get(), &QQuickItemGrabResult::ready, this, [grab]() {

            qInfo() << "<<< Utils::takeScreenshot ";

        });

    }

}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20200810/8b206fda/attachment.html>


More information about the Interest mailing list