title: How to free memory space of an image after capturing and processing in python and opencv?
body: <p>In the following code,after capturing and processing some images, this code occupy around 80% of main memory and then terminate automatically by OS.</p>
  
  <pre><code>import cv2
  import numpy as np
  capture = cv2.VideoCapture(0)
  num = 1
  RED_MIN=np.array([170,160,60],np.uint8)
  RED_MAX=np.array([180,255,255],np.uint8)
  while True:
      flag, img = capture.read()
      flag=capture.set(3,640)
      flag=capture.set(4,480)
      cv2.imwrite('pic.jpg', img)
      img1=cv2.imread('pic.jpg')
      img=cv2.blur(img1,(3,3))
      hsv_img=cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
      frame_thresh=cv2.inRange(hsv_img,RED_MIN,RED_MAX)
          contours,hierarchy=cv2.findContours(frame_thresh,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
      x_area=0
      print num
      num=num+1
      if num == 500:
          del(capture)
  </code></pre>
  
  <p>I used capture.release() in each iteration but unable to free space. When the value of num reaches to 500, it only releases the camera not main memory space that can be seen on terminal using top command.How can I free memory space after processing each image?</p>