title: How to completely free memory of cv::Mat in C++
body: <p>when I try to create a cv::Mat and release it afterwards (code below), I still have (according to valgrind) a memory leak by about 1 Byte per Pixel.</p>
  
  <p>Does anyone know how to free the memory of an cv::Mat properly?</p>
  
  <p>Thanks for ansers :)</p>
  
  <p>Code:</p>
  
  <pre><code>int main(int argc, char** argv)
  {
    cv::Mat* matrx = new cv::Mat(1000,1000,CV_8UC1,0.);
    matrx-&gt;release();
    delete matrx;
    return 0;
  }
  </code></pre>
  
  <p>Valgrind:</p>
  
  <pre><code>[...]
  ==29420==    1,000,028 bytes in 1 blocks are definitely lost in loss record 372 of 372
  ==29420==    at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
  ==29420==    by 0x5438877: cv::fastMalloc(unsigned long) (in /usr/lib/x86_64-linux-gnu/libopencv_core.so.2.4.8)
  ==29420==    by 0x536FE2A: cv::Mat::create(int, int const*, int) (in /usr/lib/x86_64-linux-gnu/libopencv_core.so.2.4.8)
  ==29420==    by 0x426FB5: cv::Mat::create(int, int, int) (mat.inl.hpp:663)
  ==29420==    by 0x426ECD: cv::Mat::Mat(int, int, int, cv::Scalar_&lt;double&gt; const&amp;) (mat.inl.hpp:347)
  ==29420==    by 0x425A09: main (main.cpp:18)
  ==29420== 
  ==29420== LEAK SUMMARY:
  ==29420==    definitely lost: 1,000,028 bytes in 1 blocks
  ==29420==    indirectly lost: 0 bytes in 0 blocks
  ==29420==      possibly lost: 5,072 bytes in 95 blocks
  ==29420==    still reachable: 304,758 bytes in 1,348 blocks
  ==29420==         suppressed: 0 bytes in 0 blocks
  [...]
  </code></pre>