Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Potential leak of an object allocated - UIViewController

My app is View based application. I got 3 viewcontrollers. (main,sub,detail) each viewcontroller has one UIView. in MainViewcontroller, there's a button to launch subView. the method is as below.

-(IBAction) LaunchSubView: (id)sender {

subViewcontroller *viewController = [[subViewcontroller alloc] init];

UIView *currentView = self.view;
[UIView transitionFromView:currentView 
                    toView:viewController.view 
                  duration:0.5 
                   options:UIViewAnimationOptionTransitionFlipFromLeft   
                completion:^(BOOL finished){}];

}

While i try build and analyze, I got this warning. Potential leak of an object allocated on line 54 and stored into 'viewController' i tried [viewController release] after transitionFromView method and subViewcontroller *viewController = [[[subViewcontroller alloc] init] autorelease]; both ways cause the app crash. any idea what am i suppose to do? thanks in advance for any kind help. =)

like image 683
moon Avatar asked Dec 04 '25 00:12

moon


1 Answers

transitionFromView:toView:duration:options:completion: is not the right method to use. You should probably be using presentModalViewController:animated:.

If you read the documentation for transitionFromView:toView:duration:options:completion: it explains:

This method modifies the views in their view hierarchy only. It does not modify your application’s view controllers in any way. For example, if you use this method to change the root view displayed by a view controller, it is your responsibility to update the view controller appropriately to handle the change."

like image 66
benwong Avatar answered Dec 06 '25 17:12

benwong