Thanks! This indeed fixes the leak. Marc
On Mon, 10 Aug 2020 at 10:49, Fabrice Mousset | GEOCEPT GmbH < [email protected]> wrote: > Hi, > > > > I am not a C++ guru, but I think your memory leak issue is linked with > QSharedPointer usage. > > I think you have to delete the connection to remove the lambda and destroy > the QSharedPointer. > > > > Like this: > > void Utils::takeScreenshot() > > { > > QQuickItem *item = m_rootView->contentItem(); > > QSharedPointer<QQuickItemGrabResult> grab = item->grabToImage(); > > if(grab.get() != nullptr) { > > connect(grab.get(), &QQuickItemGrabResult::ready, this, [grab]() { > > garb.get()->disconnect(); > > qInfo() << "<<< Utils::takeScreenshot "; > > }); > > } > > } > > > > Regards > > > > Fabrice > > > > *Von:* Interest <[email protected]> *Im Auftrag von *Marc > Van Daele > *Gesendet:* Montag, 10. August 2020 10:32 > *An:* Qt Interest <[email protected]> > *Betreff:* [Interest] Memory leak in grabToImage? > > > > 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 "; > > }); > > } > > } > >
_______________________________________________ Interest mailing list [email protected] https://lists.qt-project.org/listinfo/interest
