Qt example with memory leak
Hello.
I compiled a basic GUI example written with Qt. When I run with valgrind, it tells that there is memory leak.
It is stranger, because at each time I run the app, the number of malloc calls are different.
Qt seems nondeterministic and it does not free allocated memory.
Code:
#include <QApplication>
#include <QPushButton>
int main(int argc, char *argv[])
{
hello.resize(100, 30);
hello.show();
return app.exec();
}
Re: Qt example with memory leak
Qt does its own memory management for several classes that escapes detection by valgrind's checks for matched new/delete and malloc/free calls.
If you like, you can build a debug version of Qt and track these down yourself. When we did that, we wound up convincing ourselves that A) all the "leaks" we checked were spurious, and B) had we discovered any actual leaks, it would have been largely out of our control to fix them, since memory allocation takes place in code that could change with any future release.
Re: Qt example with memory leak
On my Linux machine with Qt 4.6.3 I see lost memory reports (possible and concrete) in libglib, libgobject, libfreetype, libX11 and few others. None of the leaks come directly from Qt.
Re: Qt example with memory leak
Is there a way to detect actual memory leaks in a code that uses Qt?
Re: Qt example with memory leak
You already have it. Valgrind is a powerful tool but it is neither a no-brainer tool nor totally infallible. This might shed some light on the types of "leaks":
http://www.linuxprogrammingblog.com/...g-memory-leaks
Re: Qt example with memory leak
IMHO valgrind is useless to debug a qt program without a suppression file. Buts very easy to create one. Write a very simple Qt Programm (only a few lines, but with QApplication, Dialog, etc; like the one in your example) and then use the Valgrind Suppression File Howto to create one. You will get far less "qt errors" and can focus on your own code. Really nice is the Valgrind Eclipse Integration. That makes valgrind usage easier (at least for me ;))