The application runs slowly after loading the view manager, then it unloads approximately 15-20 times

Usage: Xcode 4.6 ARC Storyboard segue model for SecondViewController

I have an application that has a main ViewController that loads the new veiwController when the device rotates to the right. When the application starts everything works fine. If I rotate the device, and then back, which unloads the controller of the second glance, the application is very sloppy about 15-20 times. I narrowed down that this only happens when the closed view handler loads and only when I rotate the device as malicious code. I also narrowed down, this is a memory problem. I installed an application that keeps track of used and available memory. My memory goes from 400 MB to 900 MB when I rotate the device several times. I try to give as much information as possible. Each view has 8 NSTimers that fire every second.

Is there a way to programmatically unload a view to make sure it is unloaded?

I have included this code to provide loading and unloading:

`- (void) setView: (UIView *) aView {NSLog (@" →> Enter% s <<", PRETTY_FUNCTION );

if (!aView) // view is being set to nil { NSLog(@"Should be unloading now"); } [super setView:aView]; NSLog(@"<<< Leaving %s >>>", __PRETTY_FUNCTION__); 

}

Log result: 2013-04-22 16: 42: 03.588 xxxxxxxx [xxxxxxx] →> Enter - [GraphViewController setView:] <<2013-04-22 16: 42: 03.589 xxxxxxxx [xxxxxxx] <Care - [GraphViewController setView:] →>

ʻI'm not sure what I need to fix it.

Any "points" in the right direction will be greatly appreciated.

thanks

0
ios memory-leaks rotation viewcontroller
source share
1 answer

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.

+2
source share

All Articles