UIImagePickerController crashes application after 50-60 images

I ran into a serious problem with UIImagePickerController in fast mode. After continuously capturing 50-60 images, the application crashed without registering any problems in the tricks. This is a memory problem. I tried the following solution.

@interface UIImagePickerController (Singleton) +(UIImagePickerController *) instance; @end @implementation UIImagePickerController (Singleton) +(UIImagePickerController *) instance{ static UIImagePickerController *_instance; static dispatch_once_t onceToken; dispatch_once(&onceToken,^{ _instance=[[UIImagePickerController alloc] init]; }); return _instance } if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera){ let image = UIImagePickerController.instance() //Singleton call used here image.delegate = self image.sourceType = UIImagePickerControllerSourceType.Camera image.allowEditing = true self.presentViewController(image,animated: true,completion: nil) } func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]){ autoreleasepool{ var image: UIImage? =info[UIImagePickerControllerOriginalImage] as! UIImage imageView.image = Utils.resizeAndCompress(image) image=nil } self.dismissViewControllerAnimated(true,completion: nil) } 

Any idea what's wrong here? Your help will be greatly appreciated. Thanks

 class func resizeAndCompress(image: UIImage!) -> UIImage? { let size = image.size let maxLength: CGFloat = 640.0 var newSize: CGSize if size.width > size.height { let scale = maxLength / size.width newSize = CGSizeMake(maxLength, size.height * scale) } else { let scale = maxLength / size.height newSize = CGSizeMake(size.width * scale, maxLength) } // This is the rect that we've calculated out and this is what is actually used below let rect = CGRectMake(0, 0, newSize.width, newSize.height) // Actually do the resizing to the rect using the ImageContext stuff UIGraphicsBeginImageContextWithOptions(newSize, false, 1.0) image.drawInRect(rect) let resizedImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return resizedImage } 

Crash Solution It seems the problem is with the iOS version. I created my custom image control using AVVideoCapture. Now I can capture over 1000 images.

+5
source share

All Articles