繁体   English   中英

iPhone应用程序由于内存不足而崩溃,但在模拟器中可以正常使用

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

亲爱的所有人,我有一个基于导航的应用程序,具有大约60个视图。

我已经执行以下操作:1.构建和分析:bulid成功,没有任何抱怨。 2.仪器分配和泄漏:无泄漏。

但是,该应用程序在iPhone或iPad上崩溃了,但在模拟器中运行良好。 崩溃发生在第50个视图处。 没有崩溃报告,但是我在crashreporter文件夹中确实看到LowMemory.log。

我已将iPhone和iPad升级到4.2

有谁知道可能出什么问题? 我已经阅读和故障排除了一个星期。

感谢您的所有答复。

我的应用程序有一个名为contentViewController的根视图,用户可以从此处导航到4个测验。

这是我用来返回到根视图的代码。

- (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]; 
}

}

用于推送视图的示例代码:

-(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];   

}

在模拟器下运行时,通常不会遇到内存问题,因此在此平台上不会自动遇到这些错误。

但是,模拟器确实具有可以手动触发“内存不足”事件的功能。 如果这实际上是导致设备崩溃的原因,则也可能以这种方式触发模拟器中的同一错误。

共享一些有关如何推动视图控制器的代码将使其他人可以帮助您。

您可以通过以下操作更轻松地弹出到根视图控制器:

[self.navigationController popToRootViewControllerAnimated:YES];

您实际上是在共享的代码中推送根视图控制器的新实例。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM