I have a memory leak in my OpenCV application. Its a medium size application with a dozon of classes and a few thousands lines of code. Somehow, I managed to produce a large memory leak in my application that it eats away all of my 8gb memory in a few minutes. I am using OpenCV C++ 2.3 on Ubuntu 11.10 with CMake.
It is a hand tracking application and it process two video streams simultaneusly at a frame rate of around 15fps for each camera.
I tried using valgrind like below, but the output of valgrind is so huge that exceeds the amount of text shell can keep in buffer. I know I can save the output to a log file, but I was hoping to avoid the daunting task of reading through all of it. Here is the valgrind command I used:
valgrind --tool=memcheck --leak-check=full --show-reachable=yes ./Gibbon
Here is the last few lines of valgrind output:
==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 blocks
==3573== indirectly lost: 5,414,640 bytes in 15 blocks
==3573== possibly lost: 2,314,837 bytes in 1,148 blocks
==3573== still reachable: 496,811 bytes in 4,037 blocks
==3573== suppressed: 0 bytes in 0 blocks
==3573==
==3573== For counts of detected and suppressed errors, rerun with: -v
==3573== Use --track-origins=yes to see where uninitialised values come from
==3573== ERROR SUMMARY: 336 errors from 318 contexts (suppressed: 10 from 8)
What are some better ways that I can approach this problem? Are there some tools that can show me in a concise way what function calls are causing most of the memory allocations? If valgrind is the answer, I would appreciate some hints on how to use it in a more efficient way since I am totally new to this tool.