title: Opencv; How to free IplImage*?
body: <p>I am trying to get a hang of OpenCV. At the moment I am trying to subtract two frames from each other and display the result. I have found example code which will do that just fine.
  My problem is that I am getting a memory allocation error.
  Well, nothing to special about that, because I am feeding the program with HD video.
  So my question is how do I release the allocated memory of an IplImage*?
  The Mat type has something like Mat.release().
  IplImage does not have that, nor does free(IplImage) work.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>#include &lt;opencv2\opencv.hpp&gt;
  #include &lt;opencv2\highgui\highgui.hpp&gt;
  #include &lt;opencv2\highgui\highgui_c.h&gt;
  
  
  using namespace cv;
  
  int main()
  {
      std::string videofilename;
  
      std::cout &lt;&lt; "Please specify the video name (make sure it is in the same folder\nas the application!):" &lt;&lt; std::endl;
      std::cin &gt;&gt; videofilename;
      std::cout &lt;&lt; "The name you provided: " &lt;&lt; videofilename &lt;&lt; std::endl;
  
      VideoCapture video(videofilename);
  
      if(!video.isOpened())
      {
          std::cout &lt;&lt; "Could not open video file" &lt;&lt; std::endl;
          return -1;
      }
  
      std::cout &lt;&lt; "Number of frames: " &lt;&lt; video.get(CV_CAP_PROP_FRAME_COUNT) &lt;&lt; std::endl;
      std::cout &lt;&lt; "Duration: "&lt;&lt; static_cast&lt;int&gt;(video.get(CV_CAP_PROP_FRAME_COUNT))/(30*60) &lt;&lt; "min " &lt;&lt; static_cast&lt;int&gt;((video.get(CV_CAP_PROP_FRAME_COUNT)))%(30*60)/30 &lt;&lt; "sek" &lt;&lt; std::endl;
  
      // Close it before opening for playing
      video.release();
  
      CvCapture* capture = cvCaptureFromAVI(videofilename.c_str()); 
      IplImage* frame = cvQueryFrame(capture);
      IplImage* currframe = cvCreateImage(cvGetSize(frame),IPL_DEPTH_8U,3);
      IplImage* destframe = cvCreateImage(cvGetSize(frame),IPL_DEPTH_8U,3);
  
  
      if ( !capture ) 
      {  
          std::cout &lt;&lt; "Could not open video file" &lt;&lt; std::endl;
          return -1; 
      }
  
      cvNamedWindow("dest", CV_WINDOW_AUTOSIZE);
  
      while(1)
      {
          frame = cvQueryFrame(capture);
  
          if(!frame)
          {
              printf("Capture Finished\n");
              break;
          }
  
          currframe = cvCloneImage(frame);    // copy frame to current
          frame = cvQueryFrame(capture);        // grab frame
  
          if(!frame)
          {
              printf("Capture Finished\n");
              break;
          }
  
          cvSub(frame, currframe, destframe);    // subtraction between the last frame to cur
          cvShowImage("dest", destframe);
          //cvReleaseImage(currframe); // doesn't work
          //free(currframe); // doesnt work either
          //delete(currframe); //again, no luck
          cvWaitKey(30);
      }
  
  cvDestroyWindow("dest");
  cvReleaseCapture(&amp;capture);
  return 0;
  }
  </code></pre>