简体   繁体   English

Dismiss ViewController 不释放内存

[英]Dismiss ViewController does not deallocate memory

I'm having a memory-related issue, that is, whenever I go(segue) to a second view and then go back (dismiss), the memory keeps stacking up.我有一个与内存相关的问题,也就是说,每当我转到(segue)第二个视图然后返回(关闭)时,内存就会不断堆积。

I have the following code in my second viewController.我的第二个 viewController 中有以下代码。 However, it does not deallocate memory.但是,它不会释放内存。

    override func viewWillDisappear() {
        super.viewWillDisappear()
        self.dismissController(self)
        self.removeFromParentViewController()
}

Thanks in advance.提前致谢。

Probably there is a retain cycle created.可能创建了一个保留周期。 Somewhere in the class you are passing "self" outside to another class or struct.在班级的某个地方,您正在将“自我”传递给另一个班级或结构。 Make a text search for "self" in the class.在课堂上搜索“self”。

If you need help finding the cycle post all lines which are giving away "self" here.如果您需要帮助找到周期,请在此处发布所有放弃“自我”的行。

When controller don't call dealloc, it means that you have some retain cycle.当控制器不调用 dealloc 时,这意味着您有一些保留周期。 We should read code to find where is retain.我们应该阅读代码以找到保留的位置。 So you can read through this blog and find problem with your code:所以你可以通读这个博客并找到你的代码的问题:

Retain Cycle 保留周期

If you are using present view controller, then you should use the below code如果您使用的是当前视图控制器,那么您应该使用以下代码

self.dismissViewControllerAnimated(true, completion: nil)

If you are using navigation controller push, then use the below code如果您使用的是导航控制器推送,请使用以下代码

self.navigationController?.popViewControllerAnimated(true)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM