title: Exception when deleting std::vector<unsigned char> from opencv imencode
body: <p>Im new to opencv and c++, Im forced to lean c++ to use opencv on my delphi app. So im exporting this function from dll to convert a pointer to mat back to bytes after image processing. This is the function im using:</p>
  
  <pre><code>DllExport unsigned char* MatToBytes(cv::Mat *src, int &amp;outLen)
  { 
      cv::Mat &amp;matCvrt = *src;
      std::vector&lt;unsigned char&gt; *poutVet = new std::vector&lt;unsigned char&gt;();
      std::vector&lt;unsigned char&gt; &amp;outVet = *poutVet;
      imencode(".png", matCvrt, outVet);
      outLen = outVet.size();
      unsigned char* outBytes;
      outBytes = new unsigned char[outVet.size()];
      std::copy(outVet.begin(), outVet.end(), outBytes);
      vector&lt;unsigned char&gt;().swap(outVet);
      return outBytes;
  }
  </code></pre>
  
  <p>I already researched about it whole day now but couldnt find an answer. if I remove the code</p>
  
  <pre><code>vector&lt;unsigned char&gt;().swap(outVet);
  </code></pre>
  
  <p>it would work fine, but leaks memory. if I put it in the code, I get "Debug Assertion Failed!" Hope someone can help me out, thanks a lot.</p>