memory not releasing with ARC and storyboard in iOS 5.1

我们两清 提交于 2020-01-21 08:29:13

问题


i'm cracking my head on memory issues with my app, the app are working fine except that it will crash once it hit low memory warning and are very very very laggy when using it for 10 to 20 minutes.

EDIT: how to poptoviewcontroller?

introvideo-> welcomeview & tutorialview-> mainviewcontroller-> scannerviewcontoller-> questionview ->(if answer correct -> correctView) else ->wrongView

how do i pop back to mainView controller ?

the below code are to solve adding view controller to the navigationcontroller.viewcontroller stack. As i'm using storyboard pushing from viewcontroller to another view contoller with out poping. the code will pop to the viewcontroller that are already in the viewcontroller stack.

the flow of the of my storyboard as attached:

http://dl.dropbox.com/u/418769/storyboard%20flow.png

intro video -> welcome view & tutorial view (if username !exist) -> main view controller

this is the main file that user will alway go to.

http://dl.dropbox.com/u/418769/scannerViewController.h

http://dl.dropbox.com/u/418769/scannerViewController.m

i'm using a custom segue to pop viewcontrollers, which solved part of the problem.

-(void)perform {
    UIViewController *sourceVC = (UIViewController *) self.sourceViewController;
    NSInteger index = -1;
    NSArray* arr = [[NSArray alloc] initWithArray:sourceVC.navigationController.viewControllers];
    for(int i=0 ; i<[arr count] ; i++)
    {
        if([[arr objectAtIndex:i] isKindOfClass:NSClassFromString(@"mainViewController")])
        {
            index = i;
        }       
    }    

    [UIView transitionWithView:sourceVC.navigationController.view duration:0.5
                       options:UIViewAnimationOptionTransitionCrossDissolve
                    animations:^{

                        [sourceVC.navigationController popToViewController:[arr objectAtIndex:index] animated:NO];

                    }
                    completion:^(BOOL  completed)
     {     

             }                      
     ];

}

however, the app are still eating up the RAM and VRAM.

I really appreciate any friends here to help solving my question, does Strong value caused this problem ?


回答1:


When you say that you're using a "custom segue to pop to the Main View Controller", I'm not sure if I quite understand that. Are you using performSegueWithIdentifier? If so, then you're not popping; you're pushing another copy of the main view controller!

In most storyboards, you don't see a segue out of the right side child view looping back to the left of the parent view (and your screen snapshot showed a dizzying number of segue's entering back into the main view controller, which is a bit of a red flag). This is a far more customary storyboard (taken from Beginning Storyboards in iOS 5) at Ray Wenderlich):


(source: cloudfront.net)

Usually you'll dismiss a child view with something like the follow, not use a segue.

[self.navigationController popViewControllerAnimated:YES];

Of, if you wanted to pop back multiple levels, you would use popToViewController or popToRootViewControllerAnimated. Or if you use modal segues, you would dismiss the modal with dismissViewControllerAnimated.

If I've misunderstood what you mean't by "custom segue to pop", can you provide what code you're using do to that?




回答2:


Computer-aided analysis is the way to solve this. Do Build and Analyze and resolve all issues. Run your app under the Leaks and Allocations instruments. Use heap-shot analysis.




回答3:


  1. @ken-thomases analysis is spot on. Also see Finding leaks.

  2. I presume you are using ARC?

  3. Can you explain what is the purpose of the above code sample and what your app is doing to require something like this? It feels like you're addressing a symptom rather than solving a problem.

  4. In answer to your question, the use of strong is unlikely to be the source of problems, unless you have strong reference cycles (see Transitioning to ARC). If you follow Ken's suggestions, you'll identify where your app is leaking memory (assuming it is), and if so, where it is. At that point, if you still don't understand the source of the leak, you can post the offending code here and I'm sure there will be plenty of people willing to help. Also, if you have some code that you wonder whether the strong reference is inappropriate, post that relevant code and, again, I'm sure we'll be happy to help if we can.



来源:https://stackoverflow.com/questions/10544444/memory-not-releasing-with-arc-and-storyboard-in-ios-5-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!