Ask Your Question

Revision history [back]

Valgrind Reports Possible Memory Leak using OpenCV C++ Libraries

I have created a very simple program, which essentially does nothing in particular other than include the opencv2/core/core.hpp header.

However, when I run the program using Valgrind it always reports "possibly lost: 4,676 bytes in 83 blocks" seeming to suggest that there may be a memory leak in my program or the OpenCV C++ bindings.

#include <opencv2/core/core.hpp>

int main() {
    return 0;
}

The output from Valgrind is:

==30842== Memcheck, a memory error detector
==30842== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==30842== Using Valgrind-3.10.0.SVN and LibVEX; rerun with -h for copyright info
==30842== Command: ./opencv-testing
==30842== 
==30842== 
==30842== HEAP SUMMARY:
==30842==     in use at exit: 307,778 bytes in 1,401 blocks
==30842==   total heap usage: 2,628 allocs, 1,227 frees, 400,413 bytes allocated
==30842== 
==30842== LEAK SUMMARY:
==30842==    definitely lost: 0 bytes in 0 blocks
==30842==    indirectly lost: 0 bytes in 0 blocks
==30842==    possibly lost: 4,676 bytes in 83 blocks
==30842==    still reachable: 303,102 bytes in 1,318 blocks
==30842==         suppressed: 0 bytes in 0 blocks
==30842== Rerun with --leak-check=full to see details of leaked memory
==30842== 
==30842== For counts of detected and suppressed errors, rerun with: -v
==30842== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Is OpenCV really leaking memory, or is Valgrind just misinterpreting the memory management system that OpenCV uses?

Valgrind Reports Possible Memory Leak using OpenCV C++ Libraries

I have created a very simple program, which essentially does nothing in particular other than include the opencv2/core/core.hpp header.

However, when I run the program using Valgrind it always reports "possibly lost: 4,676 bytes in 83 blocks" seeming to suggest that there may be a memory leak in my program or the OpenCV C++ bindings.

#include <opencv2/core/core.hpp>

int main() {
    return 0;
}

The output from Valgrind is:

==30842== Memcheck, a memory error detector
==30842== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==30842== Using Valgrind-3.10.0.SVN and LibVEX; rerun with -h for copyright info
==30842== Command: ./opencv-testing
==30842== 
==30842== 
==30842== HEAP SUMMARY:
==30842==     in use at exit: 307,778 bytes in 1,401 blocks
==30842==   total heap usage: 2,628 allocs, 1,227 frees, 400,413 bytes allocated
==30842== 
==30842== LEAK SUMMARY:
==30842==    definitely lost: 0 bytes in 0 blocks
==30842==    indirectly lost: 0 bytes in 0 blocks
==30842==    possibly lost: 4,676 bytes in 83 blocks
==30842==    still reachable: 303,102 bytes in 1,318 blocks
==30842==         suppressed: 0 bytes in 0 blocks
==30842== Rerun with --leak-check=full to see details of leaked memory
==30842== 
==30842== For counts of detected and suppressed errors, rerun with: -v
==30842== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Is OpenCV really leaking memory, or is Valgrind just misinterpreting the memory management system that OpenCV uses?uses? Is there a way to prevent these "possibly lost" memory errors from occurring when using OpenCV?