title: malloc errors when passing around cv:Mat references
body: <p>I am using OpenCV 2's cv::Mat structures for several objects in a game. Sometimes these are passed around directly, sometimes by a <code>cv::Mat*</code> pointer, such as when one object needs to modify another object's cv::Mat. I am used to having to manage memory myself, but I understand that cv::Mat uses reference counting. Everything seems to work most of the time, however occasionally I get the following error running in debug mode in Xcode:</p>
  
  <pre><code>malloc: *** error for object 0x3000000000000000: pointer being freed was not allocated
  *** set a breakpoint in malloc_error_break to debug
  </code></pre>
  
  <p>This occurs when I pass two cv::Mats to a function, as below:</p>
  
  <pre><code>Find(this-&gt;fillShape, shape-&gt;fillShape)
  </code></pre>
  
  <p>This error does not occur every time I run across this line though. How shall I debug this?</p>