Ask Your Question

Revision history [back]

cv::Mat leaking memory on creation?

I'm debugging a software to fix memory leaks, and for that I am using valgrind which helps locating memory leak sources. What I found is that valgrind issues a warning on every instance where a Mat is being created, here is an example:

==15040== 76,828 bytes in 1 blocks are possibly lost in loss record 6,293 of 6,339
==15040==    at 0x4C2B840: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==15040==    by 0x57D960: cv::fastMalloc(unsigned long) (in /home/batista/workspace/VUXtPan/DebugBin/VUXtPand)
==15040==    by 0x5BFB31: cv::Mat::create(int, int const*, int) (in /home/batista/workspace/VUXtPan/DebugBin/VUXtPand)
==15040==    by 0x644A18: cv::MatOp_Initializer::assign(cv::MatExpr const&, cv::Mat&, int) const (in /home/batista/workspace/VUXtPan/DebugBin/VUXtPand)
==15040==    by 0x41346A: cv::Mat::operator=(cv::MatExpr const&) (mat.hpp:1417)
==15040==    by 0x4103B3: vux::PreProcess::initializeRequiredElements(vii::Ptr<vux::SourceController>) (PreProcess.cpp:38)
==15040==    by 0x433F2B: vux::Tracker::_process() (Tracker.cpp:218)
==15040==    by 0x433B40: vux::Tracker::start(unsigned short, unsigned short, Modules) (Tracker.cpp:69)
==15040==    by 0x435D6F: main (main.cpp:8)
==15040== 

==15040== 76,828 bytes in 1 blocks are possibly lost in loss record 6,294 of 6,339
==15040==    at 0x4C2B840: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==15040==    by 0x57D960: cv::fastMalloc(unsigned long) (in /home/batista/workspace/VUXtPan/DebugBin/VUXtPand)
==15040==    by 0x5BFB31: cv::Mat::create(int, int const*, int) (in /home/batista/workspace/VUXtPan/DebugBin/VUXtPand)
==15040==    by 0x644A18: cv::MatOp_Initializer::assign(cv::MatExpr const&, cv::Mat&, int) const (in /home/batista/workspace/VUXtPan/DebugBin/VUXtPand)
==15040==    by 0x41346A: cv::Mat::operator=(cv::MatExpr const&) (mat.hpp:1417)
==15040==    by 0x410407: vux::PreProcess::initializeRequiredElements(vii::Ptr<vux::SourceController>) (PreProcess.cpp:39)
==15040==    by 0x433F2B: vux::Tracker::_process() (Tracker.cpp:218)
==15040==    by 0x433B40: vux::Tracker::start(unsigned short, unsigned short, Modules) (Tracker.cpp:69)
==15040==    by 0x435D6F: main (main.cpp:8)
==15040==

These are just two examples, as Valgrind issues this kind of warning for every cv::Mat that is being created. I know that there is an old topic concerning this issue, but no relevant conclusions were drawn there. This might be a false alarm, since Valgrind's report says that the memory is "possibly" lost.

Has anyone tried to figure this out?

cv::Mat leaking memory on creation?

I'm debugging a software to fix memory leaks, and for that I am using valgrind which helps locating memory leak sources. What I found is that valgrind issues a warning on every instance where a Mat is being created, here is an example:

==15040== 76,828 bytes in 1 blocks are possibly lost in loss record 6,293 of 6,339
==15040==    at 0x4C2B840: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==15040==    by 0x57D960: cv::fastMalloc(unsigned long) (in /home/batista/workspace/VUXtPan/DebugBin/VUXtPand)
==15040==    by 0x5BFB31: cv::Mat::create(int, int const*, int) (in /home/batista/workspace/VUXtPan/DebugBin/VUXtPand)
==15040==    by 0x644A18: cv::MatOp_Initializer::assign(cv::MatExpr const&, cv::Mat&, int) const (in /home/batista/workspace/VUXtPan/DebugBin/VUXtPand)
==15040==    by 0x41346A: cv::Mat::operator=(cv::MatExpr const&) (mat.hpp:1417)
==15040==    by 0x4103B3: vux::PreProcess::initializeRequiredElements(vii::Ptr<vux::SourceController>) (PreProcess.cpp:38)
==15040==    by 0x433F2B: vux::Tracker::_process() (Tracker.cpp:218)
==15040==    by 0x433B40: vux::Tracker::start(unsigned short, unsigned short, Modules) (Tracker.cpp:69)
==15040==    by 0x435D6F: main (main.cpp:8)
==15040== 

==15040== 76,828 bytes in 1 blocks are possibly lost in loss record 6,294 of 6,339
==15040==    at 0x4C2B840: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==15040==    by 0x57D960: cv::fastMalloc(unsigned long) (in /home/batista/workspace/VUXtPan/DebugBin/VUXtPand)
==15040==    by 0x5BFB31: cv::Mat::create(int, int const*, int) (in /home/batista/workspace/VUXtPan/DebugBin/VUXtPand)
==15040==    by 0x644A18: cv::MatOp_Initializer::assign(cv::MatExpr const&, cv::Mat&, int) const (in /home/batista/workspace/VUXtPan/DebugBin/VUXtPand)
==15040==    by 0x41346A: cv::Mat::operator=(cv::MatExpr const&) (mat.hpp:1417)
==15040==    by 0x410407: vux::PreProcess::initializeRequiredElements(vii::Ptr<vux::SourceController>) (PreProcess.cpp:39)
==15040==    by 0x433F2B: vux::Tracker::_process() (Tracker.cpp:218)
==15040==    by 0x433B40: vux::Tracker::start(unsigned short, unsigned short, Modules) (Tracker.cpp:69)
==15040==    by 0x435D6F: main (main.cpp:8)
==15040==

These are just two examples, as Valgrind issues this kind of warning for every cv::Mat that is being created. I know that there is an old topic concerning this issue, but no relevant conclusions were drawn there. This might be a false alarm, since Valgrind's report says that the memory is "possibly" lost.

Has anyone tried to figure this out?

Example:

Valgrind warns about all these initialization calls:

    _maskInteractionFilled = cv::Mat::zeros(VuxSettings::runHeight, VuxSettings::runWidth , CV_8UC1);
    _maskInductionImage = cv::Mat::zeros(VuxSettings::runHeight, VuxSettings::runWidth , CV_8UC1);
    _interactionLines = cv::Mat::zeros(VuxSettings::runHeight, VuxSettings::runWidth , CV_8UC1);
    _maskFlexi = cv::Mat::zeros(VuxSettings::runHeight, VuxSettings::runWidth , CV_8UC1);
    _fingerInteractionMask = cv::Mat::zeros(VuxSettings::runHeight, VuxSettings::runWidth , CV_8UC1);
    _outerInteractionMask = cv::Mat::zeros(VuxSettings::runHeight, VuxSettings::runWidth , CV_8UC1);
    _outerFingerInteractionMask = cv::Mat::zeros(VuxSettings::runHeight, VuxSettings::runWidth , CV_8UC1);
    _firstIRMat = cv::Mat::zeros(VuxSettings::runHeight, VuxSettings::runWidth, CV_8UC1);