Swiftで画像をライブラリからUIIMageに読み込み、画面遷移をした際にインスタンスが破棄されずメモリの消費量が上がって、アプリが落ちてしまいます。
Swift
1class StampViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate { 2 3 @IBOutlet var imageView:UIImageView! 4 5 @IBAction func camera() { 6 let imagePickController: UIImagePickerController = UIImagePickerController() 7 8 imagePickController.sourceType = UIImagePickerControllerSourceType.photoLibrary 9 imagePickController.delegate = self 10 imagePickController.allowsEditing = true 11 12 self.present(imagePickController, animated: true, completion: nil) 13 } 14 15 func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: 16 17 [String : AnyObject]) { 18 19 let image = info[UIImagePickerControllerOriginalImage] as? UIImage 20 self.imageView.image = image 21 self.imageView.image = image 22 self.dismiss(animated: true, completion: nil) 23 } 24//画面遷移⇩ 25 @IBAction func Back() { 26 let storyboard: UIStoryboard = self.storyboard! 27 let Started = storyboard.instantiateViewController(withIdentifier: "Started") 28 present(Started, animated: true, completion: nil) 29 30} 31 32 33 34 override func viewDidLoad() { 35 super.viewDidLoad() 36 37 38 } 39 40 override func didReceiveMemoryWarning() { 41 super.didReceiveMemoryWarning() 42 43 } 44 45} 46 47
Viewを閉じるときにインスタンスを破棄してメモリの消費を防ぎたいです。
そのためにどのようなプログラムが必要かわかりません。(すいません)
回答よろしくお願いします。。。
あなたの回答
tips
プレビュー