简体   繁体   English

当我转到另一个视图时,为什么不调用deinit?

[英]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.

相关问题 Swift iOS - 当作为子视图控制器添加到另一个视图控制器时,是否应该在子视图控制器中调用 Deinit? - Swift iOS -Should Deinit get called inside child View Controller when added as a child to another View Controller? 为什么没有在 UITabBarController 上调用 deinit? - Why is deinit not called on UITabBarController? 为什么不调用 deinit? - Why deinit is not called? 为什么不调用表视图委托方法? - Why the table view delegate methods don't get called? 如果我的视图控制器调用deinit(),是否意味着我没有内存泄漏? - If my view controller calls deinit(), does that mean that I don't have memory leaks? 为什么我弹出/ self时不调用deinit.dismiss我的WKInterfacecontroller - Why deinit is not called when I pop/self.dismiss my WKInterfacecontroller deinit 仅在视图控制器打开时被调用 - deinit only gets called when view controller opens 当视图控制器消失时,将调用deinit吗? - Will deinit gets called when a view controller gets disappeared? 关闭视图控制器时,在应用程序中调用了deinit,但未在单元测试中调用过deinit - deinit called in app but not in unit test when dismissing view controller 在 deinit 中的 NotificationCenter.default.removeObserver(self),为什么 deinit 它甚至被调用? - NotificationCenter.default.removeObserver(self) in deinit, why deinit it even get called?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM