我通常用 C++ 编写我的类,并在 Linux 平台上使用 valgrind 检查它们是否泄漏内存.直到所有堆内存都被释放,我才满意.
I usually write my classes in C++ and check if they leak memory using valgrind on Linux platform. I'm not satisfied until all the heap memory is freed.
开始用 Qt 编写,我发现 valgrind 检测到多少泄漏,也是在一个简单的项目中.它们太多了,很难检测到我的相同泄漏.
Starting to write in Qt, I found how many leaks valgrind detects, also on a simple project. They are so many that it's difficult to detect my same leaks.
我在某处读到可以使用 valgrind 的抑制文件,这有助于过滤掉不需要的泄漏,但我找不到它.
I read somewhere that is possibile to use a suppression files for valgrind which helps filtering out the unwanted leaks, but I can't find it.
我使用的是 Ubuntu 11.04 x64、g++ 4.5、Qt 4.7.有人知道如何处理这个问题吗?
I'm using Ubuntu 11.04 x64, g++ 4.5, Qt 4.7. Does somebody know how to cope with this problem?
您是否查看了这个Valgrind Suppression File Howto"维基?
只是为了记录,Qt中有一些底层库(尤其是绘制过程中的库)总是泄漏少量内存.这些是您需要压制的.
Just for the record there are some underlying libraries in Qt (especially the ones in the painting process) which always leak small amount of memory. These are the one you need to suppress.
如您所说,您应该首先创建一个最小项目,运行它以创建一个 valgrind 抑制文件,然后将该抑制文件应用于您的项目.
As you said, you should first create a minimal project, run it to create a valgrind suppression file and then apply that suppression file to your project.
这篇关于使用 Valgrind 抑制 Qt 内存泄漏的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!