Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenCV Mat creation produces memory leak
    text
    copied!<p>My memory is getting full fairly quick once using the next piece of code. Valgrind shows a memory leak, but everything is allocated on stack and (supposed to be) freed once the function ends. </p> <pre><code>void mult_run_time(int rows, int cols) { Mat matrix(rows,cols,CV_32SC1); Mat row_vec(cols,1,CV_32SC1); /* initialize vector and matrix */ for (int col = 0; col &lt; cols; ++col) { for (int row = 0; row &lt; rows; ++row) { matrix.at&lt;unsigned long&gt;(row,col) = rand() % ULONG_MAX; } row_vec.at&lt;unsigned long&gt;(1,col) = rand() % ULONG_MAX; } /* end initialization of vector and matrix*/ matrix*row_vec; } int main() { for (int row = 0; row &lt; 20; ++row) { for (int col = 0; col &lt; 20; ++col) { mult_run_time(row,col); } } return 0; } </code></pre> <p>Valgrind shows that there is a memory leak in line <code>Mat row_vec(cols,1,CV_32CS1)</code>:</p> <pre><code>==9201== 24,320 bytes in 380 blocks are definitely lost in loss record 50 of 50 ==9201== at 0x4026864: malloc (vg_replace_malloc.c:236) ==9201== by 0x40C0A8B: cv::fastMalloc(unsigned int) (in /usr/local/lib/libopencv_core.so.2.3.1) ==9201== by 0x41914E3: cv::Mat::create(int, int const*, int) (in /usr/local/lib/libopencv_core.so.2.3.1) ==9201== by 0x8048BE4: cv::Mat::create(int, int, int) (mat.hpp:368) ==9201== by 0x8048B2A: cv::Mat::Mat(int, int, int) (mat.hpp:68) ==9201== by 0x80488B0: mult_run_time(int, int) (mat_by_vec_mult.cpp:26) ==9201== by 0x80489F5: main (mat_by_vec_mult.cpp:59) </code></pre> <p>Is it a known bug in OpenCV or am I missing something?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload