开发者

iPhone App Crashes due to Low Memory but works fine in simulator

Dear all, I have a navigation-based app with about 60 views.

I have run with the following : 1. Build and analyse : bulid is successful with no complains. 2. Instruments allocation and leaks : no leaks.

However, the app crashed in iPhone or iPad but works fine in simulator. The crash occurs at around 50th view. There is no crash reports but I do see LowMemory.log in the crashreporter folder.

I have upgraded my iphone and ipad to 4.2

Does anyone have ideas what could be wrong? I have been reading and troubleshooting for a week.

Thank you for all the replies.

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

This is the code I use to return to my 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]; 
}

}

Sample code for pushing 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]
                  开发者_StackOverflow中文版                              initWithNibName:@"Exercise2ViewController" bundle:[NSBundle mainBundle]];
    self.exercise2ViewController = aViewController;
    [aViewController release];
}
[self.navigationController pushViewController:self.exercise2ViewController animated:YES];   

}


You will normally not run into memory problems when running under the simulator, so these errors are not automatically encountered on this platform.

The simulator does however have a feature where you can manually trigger a Low Memory event. If this is actually the cause of the crash on the device, then it might also be possible that you can trigger the same bug in the simulator in this way.


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

You can pop to root view controller more easily by doing:

[self.navigationController popToRootViewControllerAnimated:YES];

You are actually pushing a new instance of your root view controller in the code that you have shared.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜