title: How to force an opencv image (cv::Mat) to release its memory
body: <p>I have a class like this:</p>
  <pre><code>class MyClass
  {
     cv::Mat image;
  public:
     init()
     {
          image=imread(&quot;test.jpg&quot;);
     }
     cv::Mat getImage()
     {
          return image;
      }
     void reset()
     {
        // what should I write here?
      }
  }
  cv::Mat myImage;
  
  void main()
  {
      MyClass myclass;
      myclass.init();
      myImage=myclass.getImage();
      // do something with image;
      myclass.reset();
      // at this point the memory allocated by myclass.image should be released and also myImage should be invalidated (be an empty image).
  }
  </code></pre>
  <p>Note: I know that I can make the myImage a local variable and fix the problem, but I want to know how I can release the memory allocated by a cv::Mat even when the reference count is not zero.</p>
  <p>image.release() don't release the memory as there is a copy of image (myImage) and I need to make sure that the memory is released even when there is a copy of image.</p>
  <p>For people that may complain that it is not a good idea to invalidate the myImage, the class specification says that when reset is called, all images, which was created by class became invalid and if user need the image, they need to clone it before calling reset on the class.</p>
  <h1>edit1</h1>
  <p>deallocate doesn't work and it doesn't release memory.</p>