[英]Why don't the deinit get called when i go to another view?
I have a object for my viewcontroller in a navigationcontroller that don't get deinitialized when i go back and i wonder why. 我的导航控制器中有一个供我的视图控制器使用的对象,当我返回时,它不会被初始化,我想知道为什么。
This is the class 这是班
class MyLeague {
var league : League?
var fixtures : [Fixture] = []
var teams : [Team] = []
var standings : [Standing] = []
init() {
print("Creating")
}
deinit {
print("Deallocating")
}
}
Here is how i create it in the viewcontroller 这是我在ViewController中创建它的方式
let selectedLeague = MyLeague()
And this way i set the property 这样我设置属性
APIManager.shared.request(url: url, onSuccess: { [weak self] (data) in
do {
let fixtureData = try JSONDecoder().decode(FixturesResponse.self, from: data)
self?.selectedLeague.fixtures = fixtureData.api.fixtures
self?.competitionTableView.reloadData()
} catch {
print(error)
}
}) { (error) in
print(error)
}
Try using Instruments to find any retain cycles in your code. 尝试使用乐器在代码中查找任何保留周期。
You can access it from Product -> Profile Then select the Allocations tool and use it to track which object is calling your class at that frame of time when you navigate. 您可以从“产品”->“配置文件”中访问它,然后选择“分配”工具并使用它来跟踪在导航时哪个对象正在调用您的班级。 Hope this helped. 希望这会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.