比方說,我有一個類Animal
多少內存分配給UIViewController的變量
class Animal: NSObject {
var name: String = ""
var weight: Double = 0
}
在我的視圖控制器#1,我有這些對象的數組:
class ViewController1: UIViewController {
var animals: [Animal] = [ .... ]
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let v = segue.destination as? ViewController2 {
v.mammals = self.animals.filter(...) // Are my objects duplicated?
}
}
}
class ViewController2: UIViewController {
var mammals: [Animal] = [ .... ]
}
是我Animal
當我從VC1中過濾它們並將它們的子集傳遞給VC2時,對象會被複制?當我從VC2返回到VC1時(即彈出導航堆棧),mammals
中的對象是否已解除分配,釋放內存?
編輯:這會創建任何類型的任何保留週期?