Valgrind OpenCV

anc*_*jic 3 c++ opencv valgrind

这是我的测试程序:

#include "opencv2/videoio.hpp"

int main(int argc, char** argv) {
    cv::VideoCapture videoCapture(argv[1]);
    cv::Mat frame;
    videoCapture.read(frame);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我这样运行这个程序:

valgrind --leak-check=yes ./GyroRecord ./walks6/w63/39840012.avi > valgrind_output 2>&1
Run Code Online (Sandbox Code Playgroud)

这样整个输出就保存在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)
Run Code Online (Sandbox Code Playgroud)

我想将“可能丢失”的字节减少到 0。这可能吗?或者在使用 OpenCV 时我总会有一些“可能丢失”的字节?

Ted*_*gmo 6

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

抑制文件放置在/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
Run Code Online (Sandbox Code Playgroud)

valgrind在运行项目时使用这些对我帮助很大OpenCV