Qt6 C++ memory leak seemingly from main window
-
wrote on 23 Nov 2024, 10:49 last edited by
Hello,
I am writing a rather small Qt6 application in C++. I have a little experience with Qt in Python and I chose to use the QtDesigner tool to make the UI (I don't know if that's relevant but maybe). I just ran my program through Valgrind and it reported 3 KB of memory leaked (with 377 KB "still reachable" but after looking it up I can ignore those). At first I thought the issue might come from my custom graphics view, so I commented it out to try and isolate the problem but it still pops up.
The biggest, an only "definitely lost" block point back to the initialization of the QGuiApplication which is why I think it might come from the main window itself.
With the other 2 blocks coming from
QGuiApplicationPrivate::createEventDispatcher
andQWindowPrivate::create
respectively.Now I am a bit confused about where I'm going from because as far as I'm aware my application setup doesn't allocate memory on the heap so I don't know what I should free
// main.cpp int main(int argc, char* argv[]) { QApplication a(argc, argv); AutomatLab w; w.show(); return a.exec(); }
// AutomatLab.hpp class AutomatLab : public QMainWindow { Q_OBJECT private: Ui::AutomatLab ui; //GraphicView gv; public: AutomatLab(); ~AutomatLab(); };
// AutomatLab.cpp AutomatLab::AutomatLab() { ui.setupUi(this); //ui.GraphView->layout()->addWidget(&gv); this->show(); } AutomatLab::~AutomatLab() {}
I am using CMake to autogenerate the UI files into headers during compilation.
Any help is appreciated, this isn't a heavy application so memory leaks wouldn't be that serious but I would rather understand what I'm doing to not get into bad habits.
Thank you
-
Hello,
I am writing a rather small Qt6 application in C++. I have a little experience with Qt in Python and I chose to use the QtDesigner tool to make the UI (I don't know if that's relevant but maybe). I just ran my program through Valgrind and it reported 3 KB of memory leaked (with 377 KB "still reachable" but after looking it up I can ignore those). At first I thought the issue might come from my custom graphics view, so I commented it out to try and isolate the problem but it still pops up.
The biggest, an only "definitely lost" block point back to the initialization of the QGuiApplication which is why I think it might come from the main window itself.
With the other 2 blocks coming from
QGuiApplicationPrivate::createEventDispatcher
andQWindowPrivate::create
respectively.Now I am a bit confused about where I'm going from because as far as I'm aware my application setup doesn't allocate memory on the heap so I don't know what I should free
// main.cpp int main(int argc, char* argv[]) { QApplication a(argc, argv); AutomatLab w; w.show(); return a.exec(); }
// AutomatLab.hpp class AutomatLab : public QMainWindow { Q_OBJECT private: Ui::AutomatLab ui; //GraphicView gv; public: AutomatLab(); ~AutomatLab(); };
// AutomatLab.cpp AutomatLab::AutomatLab() { ui.setupUi(this); //ui.GraphView->layout()->addWidget(&gv); this->show(); } AutomatLab::~AutomatLab() {}
I am using CMake to autogenerate the UI files into headers during compilation.
Any help is appreciated, this isn't a heavy application so memory leaks wouldn't be that serious but I would rather understand what I'm doing to not get into bad habits.
Thank you
wrote on 23 Nov 2024, 12:09 last edited byThe code you show doesn't have any obvious memory leaks...
The...Private
classes are part of Qt's internals and there are also no leaks, for sure.Sometimes Valgrind or other tools report false positives because they can't analyze the object relations properly.
-
The code you show doesn't have any obvious memory leaks...
The...Private
classes are part of Qt's internals and there are also no leaks, for sure.Sometimes Valgrind or other tools report false positives because they can't analyze the object relations properly.
wrote on 24 Nov 2024, 12:51 last edited byThank you for your feedback, I'm fairly experienced with plain C++ but not very with Qt or using Valgrind with external dependencies so I was a bit confused about what was happening.
I'll keep that in mind in the future!
-
3/3