瓦尔格林德公开简历

Valgrind OpenCV

本文关键字:林德公      更新时间:2023-10-16

这是我的测试程序:

#include "opencv2/videoio.hpp"
int main(int argc, char** argv) {
    cv::VideoCapture videoCapture(argv[1]);
    cv::Mat frame;
    videoCapture.read(frame);
    return 0;
}

我像这样运行这个程序:

valgrind --leak-check=yes ./GyroRecord ./walks6/w63/39840012.avi > valgrind_output 2>&1

以便将整个输出保存在valgrind_output文件中。

valgrind_output的内容可以在这里查看。

但是,如果链接在将来死亡,则摘要如下:

==9677== LEAK SUMMARY:
==9677==    definitely lost: 0 bytes in 0 blocks
==9677==    indirectly lost: 0 bytes in 0 blocks
==9677==      possibly lost: 1,352 bytes in 18 blocks
==9677==    still reachable: 166,408 bytes in 1,296 blocks
==9677==                       of which reachable via heuristic:
==9677==                         newarray           : 1,536 bytes in 16 blocks
==9677==         suppressed: 0 bytes in 0 blocks
==9677== Reachable blocks (those to which a pointer was found) are not shown.
==9677== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==9677== 
==9677== For counts of detected and suppressed errors, rerun with: -v
==9677== ERROR SUMMARY: 18 errors from 18 contexts (suppressed: 0 from 0)

我想将"可能丢失"的字节减少到 0。这可能吗?还是在使用OpenCV时,我总是会有一些"可能丢失"的字节?

OpenCV附带了valgrind的抑制文件(扩展名为.supp),可用于隐藏有关已分配资源的消息(通常在程序执行的早期),这些消息将被保留分配,直到程序死亡并且操作系统必须清理混乱。

抑制文件放置在/usr/share/OpenCV(在我的系统上)中:

例:

valgrind --leak-check=yes --suppressions=/usr/share/OpenCV/valgrind.supp --suppressions=/usr/share/OpenCV/valgrind_3rdparty.supp ./GyroRecord ./walks6/w63/39840012.avi

OpenCV项目上运行valgrind时,使用这些对我有很大帮助。