使用相机时如何清除记忆?

时间:2018-02-06 04:13:54

标签: ios swift xcode memory-leaks camera

我正在尝试创建一个相机应用程序,但内存泄漏 我可以清除PhotoLibrary的缓存但不能清除Camera的缓存 拍摄约40张照片后应用程序将会停机 我怎样才能清除记忆?

// After taking a picture
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
    if info[UIImagePickerControllerOriginalImage] != nil {
        let image = info[UIImagePickerControllerOriginalImage] as! UIImage
        var orientation: Int?

        if isNewPhoto == true {
            UIImageWriteToSavedPhotosAlbum(image, self, #selector(BaseResultViewController.image(_:didFinishSavingWithError:contextInfo:)), nil)
            let metadata = info[UIImagePickerControllerMediaMetadata] as? NSDictionary
            orientation = metadata?.objectForKey("Orientation") as? Int
        }
        else {
            switch image.imageOrientation.rawValue {
                case 0:
                    orientation = 1
                case 1:
                    orientation = 3
                case 2:
                    orientation = 8
                case 3:
                    orientation = 6
                default:
                    break
            }
        }

        let uuid = NSUUID().UUIDString
        let imageName = "\(uuid).PNG"
        let jpgImageName = "\(uuid)-thumb.JPG"
        let data = UIImagePNGRepresentation(image)
        let jpgData = UIImageJPEGRepresentation(image, 0.7)
        let localPath = relationData.setFile(imageName, data: data!)
        let _ = relationData.setFile(jpgImageName, data: jpgData!)

        getViewIns()?.hideActionSheet()
        baseModel.saveValuable(NSURL(fileURLWithPath: localPath), orientation: orientation)
        prepareSegue(true)
        resetValuable()
    }
    picker.dismissViewControllerAnimated(true, completion: nil)
}

0 个答案:

没有答案