title: Preventing UIImagePicker memory problems
body: <p>I am having  tough time with getting UIImagePickerController to work. It always crashes with memory error. These are the things I have done. Please advice what I can do differently.</p>
  
  <p>I am using NSOperationQueue to do the save operation in a different thread.</p>
  
  <p>I am not passing the UIImage which can be large, so I write the image to photo album and pass the NSURL of the asset.</p>
  
  <pre><code>- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [self dismissViewControllerAnimated:YES completion:^{
      UIImage *chosenImage = info[UIImagePickerControllerOriginalImage];
      NSMutableDictionary *mutable = [[info objectForKey:UIImagePickerControllerMediaMetadata] mutableCopy];
      NSBlockOperation *saveOp = [NSBlockOperation blockOperationWithBlock:^{
        [[MyViewController defaultAssetsLibrary] writeImageToSavedPhotosAlbum:[chosenImage CGImage] metadata:mutable completionBlock:^(NSURL *assetURL, NSError *error) {
          if ([self.delegate respondsToSelector:@selector(imageSelected:)]) {
              [self.delegate imageSelected:assetURL];
          }
        }];
      }];
      [saveOp setCompletionBlock:^{
      }];
      NSOperationQueue *queue = [[NSOperationQueue alloc] init];
      [queue addOperation:saveOp];
    }]; 
  }    
  </code></pre>