IPhone app crashes due to low memory, but works fine in simulator

Honey, I have a navigation app with about 60 views.

I did the following: 1. Build and analyze: bulid successfully, no complaints. 2. Appliance distribution and leakage: no leakage.

However, the app crashed on iPhone or iPad, but works fine in the simulator. The crash occurs at about 50th place. There are no crash reports, but I can see LowMemory.log in the crashreporter folder.

I have updated my iphone and ipad to 4.2

Does anyone have any idea what might be wrong? I've been reading and troubleshooting for a week.

Thanks for all the answers.

My app has a root view called contentViewController and users can navigate to 4 polls from here.

This is the code I am using to return to the root view.

- (void)goHome {
UIAlertView *alert = [[UIAlertView alloc]
                      initWithTitle: @"Warning"
                      message: @"Proceed?"
                      delegate: self
                      cancelButtonTitle:@"Yes"
                      otherButtonTitles:@"No",nil];
[alert show];
[alert release];

      

}

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
[[self navigationController] setNavigationBarHidden:NO animated:YES];
if (buttonIndex == 0) {
    NSArray * subviews = [self.view subviews];
    [subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    self.view = nil;
    if (self.contentViewController == nil)
    {
        ContentViewController *aViewController = [[ContentViewController alloc]
                                                  initWithNibName:@"ContentViewController" bundle:[NSBundle mainBundle]];
        self.contentViewController = aViewController;
        [aViewController release];
    }
    [self.navigationController pushViewController:self.contentViewController animated:YES]; 
}

      

}

Example code for displaying views:

-(IBAction) buttonArrowClicked:(id)sender {
NSURL *tapSound   = [[NSBundle mainBundle] URLForResource: @"click"
                                            withExtension: @"aif"];

// Store the URL as a CFURLRef instance
self.soundFileURLRef = (CFURLRef) [tapSound retain];

// Create a system sound object representing the sound file.
AudioServicesCreateSystemSoundID (

                                  soundFileURLRef,
                                  &soundFileObject
                                  );
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

if (![[defaults stringForKey:@"sound"] isEqualToString:@"NO"]) {
    AudioServicesPlaySystemSound (soundFileObject);
}       

if (self.exercise2ViewController == nil)
{
    Exercise2ViewController *aViewController = [[Exercise2ViewController alloc]
                                                initWithNibName:@"Exercise2ViewController" bundle:[NSBundle mainBundle]];
    self.exercise2ViewController = aViewController;
    [aViewController release];
}
[self.navigationController pushViewController:self.exercise2ViewController animated:YES];   

      

}

0


source to share


2 answers


You usually don't run into memory issues while running under the simulator, so these errors don't automatically occur on this platform.



However, the simulator has a feature to manually trigger a low memory event. If this is in fact the cause of the crash on the device, it is also possible that you can cause the same error in the simulator this way.

+3


source


Sharing some code about how you push view controllers will allow others to help you with this.

You can more easily navigate to the root view controller:



[self.navigationController popToRootViewControllerAnimated:YES];

      

You are effectively pushing a new instance of your root view controller in the code you split up.

0


source







All Articles