Kerberos
Kerberos

Reputation: 4166

iOS - Custom segue memory leak

I've two viewcontrollers with a custom segue fired by swipe gesture recognizer.

The custom segue is this:

-(void)perform{
UIViewController *sourceViewController = (UIViewController*)[self sourceViewController];
UIViewController *destinationController = (UIViewController*)[self destinationViewController];

CATransition* transition = [CATransition animation];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;

[sourceViewController.navigationController.view.layer addAnimation:transition forKey:kCATransition];
[sourceViewController.navigationController pushViewController:destinationController animated:NO];
}

It works but it increments memory each time, I found this solution: how to clear memory of previous ViewController

But if in the viewController name I put the main viewController when I swipe It goes to itself, if I put the secondViewController name it crashes.

How can I resolve the memory problem? Thanks at all.

Upvotes: 0

Views: 669

Answers (1)

micantox
micantox

Reputation: 5616

If I understand your question correctly, it's only natural that the memory increases with each segue performed, as, for its very nature, the navigation controller keeps pushing onto its stack every new controller you add. It is not a leak, as you can still get the pointers to those view controllers from the navigation controller stack, and a leak happens when you loose every reference to a portion of memory. There's no escaping from this increment in memory when using a navigation controller, it is its intended use (you could, however, release any resource that each source view controller is using and could recreate when needed before pushing the new view controller onto the stack).

Maybe the problem is that you don't want to use a navigation controller? If you could give more details about what you want to accomplish I could maybe be more helpful.

Upvotes: 1

Related Questions