title: Failed to enable connection: out of resource error PiCamera
body: <p>I am creating my thesis device which uses a PiCam. My problem is that every time I use my camera after it captures an image, it can't be used again and display an error when I click the button on my GUI to start the camera again:</p>
  
  <p>picamera.exc.PiCameraMMALError: Failed to enable connection: Out of resources</p>
  
  <p>How can I stop the camera in a way after it captures an image it also stops the using of the resource for the picamera? </p>
  
  <p>This is my code for my camera:</p>
  
  <pre><code>def startcam():
          camera = PiCamera()
          GPIO.output(16, True)
          filename = datetime.datetime.now().strftime("%Y-%m-%d-%H.%M.%S.jpg")
          time.sleep(2)
          camera.start_preview()
          sleep(1)
          GPIO.output(16, False)
          GPIO.output(13, True)
          camera.capture(filename)
          GPIO.output(13, False)
          sleep(1)
          camera.stop_preview()
          webbrowser.open(filename)
  </code></pre>
  
  <p>The GPIO codes are for my LED flash and IR led cuz I am using a NOIR camera.</p>
  
  <p>Thanks.</p>