3
votes

I am designing a game with 6 view controllers.

I use modal segues to navigate forward and unwind segues to navigate back.

The game flow through the view controllers is A -> B -> C -> D -> E -> F.

When I try to unwind from F to A dealloc is only called on B and C. This means that each time the game is played the memory used is constantly increasing.

I initially thought the problem was due to something being retained causing dealloc not to be called on view controllers D and E. However, if I set the unwind segue to go from F to D dealloc is called for both F and E which would seem to rule out this as the problem.

I also have a route directly to from view controller A to F. When I unwind in this case dealloc is called on F correctly.

View controllers F and C call the same unwind action on A. I assume this isn't the cause as I have tried changing it to use unique unwind actions for each view controller.

Any thoughts on what is causing this? I have copied some of the code used below. Please let me know what other code (if any) would be helpful in resolving this. Any help would be greatly appreciated.

Unwind action as below:

- (IBAction)unwindToMainMenu:(UIStoryboardSegue *)unwindSegue
{}

Call to trigger unwind segue from view controller F to A:

[self performSegueWithIdentifier:@"ReturnToMainMenu" sender:self];
1
Have you tried using the "Leaks" instrument, which can point out retain cycles and give you a history of all retains/releases for any object?Jesse Rusak
I have tried leaks instrument but I am not too familiar with it. It pointed me to PrepareForSegue being where the issue was but I'm not sure how to interpret it. I am fairly new to iOS development :)user1980555
Well, there's no way we can help with the information you've provided, so I would either suggest watching some WWDC videos on how to use instruments, or else create a minimal sample project that shows the problem you're seeing so we can help.Jesse Rusak
What information would help? I can provide more code, just didn't want to throw all my code at the page :)user1980555
You should try to create a minimal example: stackoverflow.com/help/mcveJesse Rusak

1 Answers

1
votes

Following your description, the problem should be on D. Probably D is retained from someone else and so it is not deallocated when you go from F directly to A. Being not deallocated it continue to retains E which retains F.

So, be concentrate on D ;)