我有一个ViewController,它的子视图imageView填充了整个vc,当我呈现新vc并去掉旧vc时,调用了旧vc的deinit,但内存仍然存在,仪器显示我与imageio有关,主要问题是为什么调用了旧vc的deinit,但内存中出现了图像。。这是我的旧VC代码:
class Vc1: UIViewController {
@IBOutlet weak var vcimage: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
vcimage.image = UIImage.init(named: "splash")
// Do any additional setup after loading the view.
}
@IBAction func tovc2(_ sender: Any) {
let vc = self.storyboard?.instantiateViewController(withIdentifier: "vc2")
AnimateTovc(ViewControllerToAnimate: vc!, vctoDissmiss: self)
}
override func didReceiveMemoryWarning() {
print("memory warning")
}
func AnimateTovc(duration:Float = 0.5,Animateoption:UIViewAnimationOptions = .transitionFlipFromLeft,ViewControllerToAnimate vc:UIViewController,vctoDissmiss: UIViewController?,completion : @escaping ()->Void = {} ){
let appDelegate = UIApplication.shared.delegate as! AppDelegate
UIView.transition(with: appDelegate.window!, duration: TimeInterval(duration), options: Animateoption , animations: { () -> Void in
appDelegate.window!.rootViewController = vc
}, completion:{ isfinished in
completion()
vctoDissmiss?.dismiss(animated: false, completion: nil)
})
}
deinit {
print("removed \(self) from memory")
}
}
奇怪的是,在newvc中,当应用程序进入后台时,内存被释放,imageio部分从内存中释放。