5

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.

Willjay
  • 6,381
  • 4
  • 33
  • 58
  • The problem could be not in the dismissed controller, but in some objects that remains in memory. Did you try any instruments, like "Leaks"? – Dmitri Pavlutin Dec 30 '15 at 07:35

3 Answers3

3

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.

Darko
  • 9,655
  • 9
  • 36
  • 48
2

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

vien vu
  • 4,277
  • 2
  • 17
  • 30
0

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)