相关疑难解决方法(0)

在OpenCV应用程序中,如何识别内存泄漏源并进行修复?

我的OpenCV应用程序中有内存泄漏.它是一个中等大小的应用程序,具有类的dozon和几千行代码.不知何故,我设法在我的应用程序中产生了大量的内存泄漏,它在几分钟内就耗尽了我所有的8GB内存.我在使用CMake的Ubuntu 11.10上使用OpenCV C++ 2.3.

我终止应用程序后立即释放了多少内存的快照. 我可以在几分钟内看到用过的内存高达4gig

它是一个手动跟踪应用程序,它以每帧15fps的帧速率同时处理两个视频流.

我尝试使用valgrind,如下所示,但valgrind的输出是如此巨大,以至于超出了文本shell可以保留在缓冲区中的数量.我知道我可以将输出保存到日志文件中,但我希望避免阅读所有内容的艰巨任务.这是我使用的valgrind命令:

valgrind --tool=memcheck --leak-check=full --show-reachable=yes ./Gibbon 
Run Code Online (Sandbox Code Playgroud)

这是valgrind输出的最后几行:

==3573== 5,415,576 (1,176 direct, 5,414,400 indirect) bytes in 7 blocks are definitely lost in loss record 2,571 of 2,571
==3573==    at 0x4C28F9F: malloc (vg_replace_malloc.c:236)
==3573==    by 0x5B2ACD0: cv::fastMalloc(unsigned long) (in /usr/local/lib/libopencv_core.so.2.3.1)
==3573==    by 0x5A7FA9D: cvCreateImageHeader (in /usr/local/lib/libopencv_core.so.2.3.1)
==3573==    by 0x484538: CameraPGR::convertImageToOpenCV(FlyCapture2::Image*) (CameraPGR.cpp:212)
==3573==    by 0x483F52: CameraPGR::grabImage() (CameraPGR.cpp:134)
==3573==    by 0x473F86: start() (GibbonMain.cpp:368)
==3573==    by 0x4725CC: main (GibbonMain.cpp:108)
==3573== 
==3573== LEAK SUMMARY:
==3573==    definitely lost: 24,432 bytes in 33 …
Run Code Online (Sandbox Code Playgroud)

c++ opencv memory-leaks

5
推荐指数
1
解决办法
2991
查看次数

标签 统计

c++ ×1

memory-leaks ×1

opencv ×1