title: Memory leak processing cv::Mat array in opencv
body: <p>I tried to draw 10 * 10 matrix on a video frame and here is the drawing function:</p>
  
  <pre><code>void AddMatrixToVideo::process(cv::Mat &amp;videoFrameInput)
  {
      int MatrixStartPointX = 0;
      int MatrixStartPointY = 0;
      int m,n;
  
      for(int i = 0; i &lt; matrixNumInRow; ++i) {
          for(int j = 0; j &lt; matrixNumInColm; ++j) {
              //draw horizontal line
              for(m = MatrixStartPointX; m &lt; MatrixStartPointX + matrixWidth; ++m) {
                      processGrayFrame(m,MatrixStartPointY,videoFrameInput);
                      processGrayFrame(m,MatrixStartPointY + matrixHeight,videoFrameInput);
              }
              //draw vertical line
              for(n = MatrixStartPointY; n &lt; MatrixStartPointY + matrixHeight; ++n) {
  //                    processGrayFrame(MatrixStartPointX,n,videoFrameInput);
  //                    processGrayFrame(MatrixStartPointX + matrixWidth,n,videoFrameInput);
              }
              MatrixStartPointX += matrixWidth;
          }
          MatrixStartPointX = 0;
          MatrixStartPointY += matrixHeight;
      }
  }
  </code></pre>
  
  <p>Here is the processGrayFrame():</p>
  
  <pre><code>void AddMatrixToVideo::processGrayFrame(int x,int y,cv::Mat &amp;videoFrameInput)
  {
      videoFrameInput.at&lt;uchar&gt;(y,x) = 255;
  }
  </code></pre>
  
  <p>After running the program, it seems that the drawing progress works the memory usage keeps increasing and finally run out of memory.
  If I comment the processGrameFrame() function, the memory problem goes(of course it won't draw lines any more). So my question is why does the assigning operation cause the memory leak problem?</p>