Qt And Valgrind Memory Analyzer
I'm a little confused about using valgrind with Qt Creator. I was troubled after running the analzyer on my current project to find that there were a couple hundred possible memory leaks. First, I didn't see any leaks until I turned on "External Errors". I don't quite understand that. But, also, none of the leaks seemed to point to anything I had actually written. They were all coming from the QApplication instantiation. So I decided to create a simple Widgets application and see how it did with the memory analyzer. That project also shows up a couple hundred possible memory leaks. So, are all of these leaks false positives? The more QWidgets I had to my project, the larger the list of leaks becomes, but none of them ever seem to be tied back to any of my code. They always seem to be linked specifically to the Q objects themselves.
Here is an example of the kind of leaks it is reporting:
@212 bytes in 1 blocks are possibly lost in loss record 6,547 of 7,114
in main in /home/kabbotta/workspace/cpp/TimeTracker/main.cpp:10
1: realloc in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so
2: g_realloc in /usr/lib/libglib-2.0.so.0.4200.1
3: g_realloc_n in /usr/lib/libglib-2.0.so.0.4200.1
6: g_type_register_static in /usr/lib/libgobject-2.0.so.0.4200.1
7: g_enum_register_static in /usr/lib/libgobject-2.0.so.0.4200.1
8: gtk_tree_view_grid_lines_get_type in /usr/lib/libgtk-x11-2.0.so.0.2400.25
10: g_type_class_ref in /usr/lib/libgobject-2.0.so.0.4200.1
11: g_object_newv in /usr/lib/libgobject-2.0.so.0.4200.1
12: g_object_new in /usr/lib/libgobject-2.0.so.0.4200.1
13: gtk_tree_view_new in /usr/lib/libgtk-x11-2.0.so.0.2400.25
18: QStyleFactory::create(QString const&) in /usr/lib/libQt5Widgets.so.5.4.0
19: QApplication::style() in /usr/lib/libQt5Widgets.so.5.4.0
20: QApplicationPrivate::initialize() in /usr/lib/libQt5Widgets.so.5.4.0
21: QApplicationPrivate::construct() in /usr/lib/libQt5Widgets.so.5.4.0
22: QApplication::QApplication(int&, char**, int) in /usr/lib/libQt5Widgets.so.5.4.0
23: main in /home/kabbotta/workspace/cpp/TimeTracker/main.cpp:10
Line 10 in main.cpp is the line where I instantiate the QApplication object.
It looks like "dealing":http://doc.qt.io/qtcreator/creator-analyzer.html#suppressing-errors with errors from used libraries is something users need to take care of.