1

I am using swift to perform segue programatically. First, I created a segue between two controllers in storyboard. Below is the code to show a view controller:

self.performSegueWithIdentifier("EditImage", sender: imageSampleBuffer)

When executing the above code, a new controller view will be presented on the UI. Then I click the "back" button on the top-left corner. The ui will come back to the previous view. It works fine here. But when I profile my app with instrument I found that the controller(pointed by "EditImage" segue) not released. When I click the controller instance on instrument, it shows that the above code is referencing this controller instance. When I perform these two controller back and forth, the instance number of that controller keep increasing. I didn't create any action function for the "back" button. All uses the default logic with navigation controller. So how to release controller when come back? Should I write any code on go back action?

Joey Yi Zhao
  • 37,514
  • 71
  • 268
  • 523

2 Answers2

0

In the UIViewController that is not been release add a deinit method and place add a breakpoint there, you will find if there is any other object keeping that reference form outside. Any public var could keep that reference, that's why all delegates should has weak reference. example

Community
  • 1
  • 1
TomCobo
  • 2,886
  • 3
  • 25
  • 43
-1

I did find a reference problem in my code. I cleared that reference in viewDidDisappear() method then it works fine. But I don't understand why instrument didn't give me the correct place where is holding my controller instance.

Joey Yi Zhao
  • 37,514
  • 71
  • 268
  • 523