QT detects memory leaks
In Linux Qt Creator, there is a Valgrind memory profiler, which is used to detect whether the application has memory leaks
Install:
sudo apt-get install valgrind
How to use the Valgrind memory profiler
1. Start the Valgrind memory profiler
2. Analyzed many places with suspicious memory leaks. Take the following as an example:
The blue line in the picture above means it is in the Qt library , so we don't need to worry about it.
See the red line , it is in our project position, and then enter the func() function , and find that the *trans pointer may not have a Qt parent object, so it cannot be automatically released
It should be noted that: Valgrind memory analyzer analyzes suspicious objects, not necessarily memory leaks.
3. Then by printing, it is found that the address of its parent object is indeed 0:
4. After specifying the Qt parent object, and then analyze the memory again, you can see that there is no memory leak in the project: