1

I am removing viewController from controller hierarchy with removeFromParentViewController, but deinit of view controller not get called. How can I check what holds strong reference on it?

Any way to see reference graph exist in memory?

This is how my swap` method looks like:

public class func swap(fromViewController: UIViewController!, toViewController: UIViewController!, containerViewController: UIViewController!) {

    fromViewController.willMoveToParentViewController(nil)
    containerViewController.addChildViewController(toViewController)
    toViewController.view.frame = containerViewController.view.bounds

    containerViewController.transitionFromViewController(fromViewController, toViewController: toViewController, duration: 0.2, options: UIViewAnimationOptions.TransitionCrossDissolve, animations: {}, completion: {finished in
        fromViewController.removeFromParentViewController()
        toViewController.didMoveToParentViewController(containerViewController)
    })
}

In transitionFromViewController completion should I add / remove destination / source views?

Any way to access refCount of a viewController in Swift?


I tried to analyse code with Instruments. Figure out what hold strong reference to view controller, but couldn't figure out. Any help?

enter image description here enter image description here

János
  • 32,867
  • 38
  • 193
  • 353
  • in Swift `dealloc` is called `deinit`, and I guess I forget to remove the view?! – János May 28 '15 at 11:13
  • Could you use viewWillDisappear to achieve your goals? – Tim May 28 '15 at 11:35
  • 1
    @bteapot `func transitionFromViewController(, toViewController:, duration:, options:, animations:, completion:)` handles the views. – Jeffery Thomas May 28 '15 at 11:37
  • @Tim finally I used `viewWillDisappear` approach to remove strong references from array and so viewController get `deinit`ed – János May 28 '15 at 11:50

1 Answers1

3

You can use profile the code with Instruments. In Xcode, select Product > Profile. When Instruments loads, select Allocations as the template.

This will allow you to trace which objects are setting what strong references.

Jeffery Thomas
  • 42,202
  • 8
  • 92
  • 117
  • I tried figure out what holds reference to my `MovieTableViewController` but hard to say. Any suggestion? I have edited the question. – János Jul 02 '15 at 11:34
  • @János First, I would look for strong delegates, and blocks for retain cycles. The profile tool should point these cycles out to you. – Jeffery Thomas Jul 02 '15 at 16:48