所以我在這裏有這個問題,當我在控制器中選擇多個圖像時,我的記憶變得瘋狂。如下所示,我將圖像轉換並存儲在CoreData中,因爲我需要稍後將它們發送到服務器。 當圖像轉換時,內存上升很多,我不知道如何解決這個問題。當你在集合視圖中顯示圖像時,它正常地將內存從30MB增加到100MB,以顯示10張圖像?內存問題,收集視圖,coredata
func elcImagePickerController(picker: ELCImagePickerController!, didFinishPickingMediaWithInfo info: [AnyObject]!) {
if (info.count == 0) {
return
}
var pickedImages = NSMutableArray()
var newImage = [UIImage()]
for any in info {
let dict = any as! NSMutableDictionary
let image = dict.objectForKey(UIImagePickerControllerOriginalImage) as! UIImage
newImage.append(image)
pickedImages.addObject(image)
println("Saving the image as binary data")
println(" ")
databaseHelper().createImage(image)
// look at the button for the createImage func
}
println("Adding selected images to image view", info.count)
self.pickerImages = newImage
self.pickerImages.removeAtIndex(0)
self.collectionView.reloadData()
self.dismissViewControllerAnimated(true, completion: nil)
println(" ")
}
func createImage(image: UIImage) {
let fetchRequest = NSFetchRequest(entityName: "Settings")
if let fetchResults = self.managedObjectContext!.executeFetchRequest(fetchRequest, error: nil) as? [Settings] {
let newImage = NSEntityDescription.insertNewObjectForEntityForName("Image", inManagedObjectContext: self.managedObjectContext!) as! Image
let convertImage = UIImageJPEGRepresentation(image, CGFloat(fetchResults[0].imageQuality))
newImage.setValue(convertImage, forKey: "pickedImage")
}
}
沒有人知道我可以如何改進? :( –