You did not provide much information about how you “unload” the SecondViewController. Do you also make a modal transition? If so, then your problem is that every time you run segue you create a new view controller, and if these are modal segments, the presented controller has a strong pointer to the representing controller, so none of these controllers will ever be freed as you go roundtrip.
Generally, you should never go backwards in a storyboard using anything other than unwinding. So, the solution to your problem is to use a break to go from the SecondViewController back to the MainViewController - this will actually return to the same instance of MainViewController from which you came, and SecondViewController will be freed. If you do not know how to do unwinding, I will edit my answer to show you how to do it.
After editing:
To do unwinding, you do two things. In the controller that you are returning to, you add a method - two important things - this is IBAction and that it has the only argument that was introduced in UIStoryboardSegue *. It doesn't matter what you call it, and you don’t even need to have any code inside it, although I usually add a log statement to make sure that it calls. Then, in IB, in the controller from which you disconnect, you control the drag from your user interface element as a button or table element (or from the controller itself, if you want to run it from the code), up to the green exit icon on the bottom scenes - it is important to note that you drag the UI element to the exit icon in the same controller, and not between the controllers. When you release the drag on the exit icon, you will see some methods that you created with the signature mentioned above. Choose the one you want and him. You can implement prepareForSegue in the source controller, just like any other segment, if you want to pass any information back to the destination controller.
rdelmar
source share