title: Memory leak in javacv
body: <p>I'm trying to make a program that takes a picture from a webcam, and afterwards resizes it, converts it to HSV, and makes some thresholding on it, to find a specific color. After this is done, I use the thresholded image to find contours, and print the x,y coords of the different contours. This is repeated over and over, to make the processing from the webcam realtime.</p>
  
  <p>It all works quite well, except for the fact that I am using up about 100 mb of RAM every 2 second it runs.</p>
  
  <p>So far I have discovered that if I use a static picture, instead of the live images from the webcam, I can minimize the memory leak significantly, although still there is memory being consumed.</p>
  
  <p>Below my code is:</p>
  
  <pre><code>public class Application {
  private CaptureImage ci;
  private ImageUtils iu;
  private CanvasFrame canvasContours;
  
  IplImage grabbedFrame;
  IplImage resizedFrame;
  IplImage thresholdedFrame;
  IplImage clonedImage;
  
  public Application(){
      ci = new CaptureImage();
      iu = new ImageUtils();
      canvasContours = new CanvasFrame("contours");
  
  }
  
  public void frameProcessing(){
  
      grabbedFrame = ci.grabImage();
      //below call used for testing purposes
      //grabbedFrame = (IplImage) opencv_highgui.cvLoadImage("testingImage.jpg");
      //cloning image due to highgui guidelines.
      clonedImage = opencv_core.cvCloneImage(grabbedFrame);
      resizedFrame = iu.resizeImage(clonedImage);
  
      opencv_core.cvReleaseImage(clonedImage);
  
      thresholdedFrame = iu.thresholdImage(resizedFrame);
  
  
      IplImage contoursFrame = iu.findContours(thresholdedFrame, resizedFrame);
  
      canvasContours.showImage(contoursFrame);
  
  
  }
  }
  </code></pre>
  
  <p>The grabImage is just the standard frameGrabber from javacv, which looks like this:</p>
  
  <pre><code>public class CaptureImage {
  private final OpenCVFrameGrabber grabber;
  private IplImage img = null;
  
  
  public CaptureImage(){
      // 0-default camera, 1 - next...so on
              grabber = new OpenCVFrameGrabber(0);
              try {
                  grabber.start();
              } catch (Exception e) {
                  System.err.print("Failed to initialize camera");
                  e.printStackTrace();
              }
  
  }
  
  public IplImage grabImage(){
  
      try {
  
      //A grabbed image from Logitech webcam is in following resolution: 1200x800px
  
          img = grabber.grab();
  
  
  
      } catch (Exception e) {
  
          e.printStackTrace();
      }
      return img;
  }
  </code></pre>
  
  <p>I appreciate any help you can give me, and if you need any more information, please just ask!</p>
  
  <p>/Jesper</p>