Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

I have the following code in my second viewController. However, it does not deallocate memory.

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

Thanks in advance.

like image 246
Willjay Avatar asked Dec 30 '15 07:12

Willjay


2 Answers

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.

If you need help finding the cycle post all lines which are giving away "self" here.

like image 147
Darko Avatar answered Sep 22 '22 16:09

Darko


When controller don't call dealloc, it means that you have some retain cycle. We should read code to find where is retain. So you can read through this blog and find problem with your code:

Retain Cycle

like image 27
vien vu Avatar answered Sep 20 '22 16:09

vien vu