简体   繁体   English

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

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

Dear all, I have a navigation-based app with about 60 views. 亲爱的所有人,我有一个基于导航的应用程序,具有大约60个视图。

I have run with the following : 1. Build and analyse : bulid is successful with no complains. 我已经执行以下操作:1.构建和分析:bulid成功,没有任何抱怨。 2. Instruments allocation and leaks : no leaks. 2.仪器分配和泄漏:无泄漏。

However, the app crashed in iPhone or iPad but works fine in simulator. 但是,该应用程序在iPhone或iPad上崩溃了,但在模拟器中运行良好。 The crash occurs at around 50th view. 崩溃发生在第50个视图处。 There is no crash reports but I do see LowMemory.log in the crashreporter folder. 没有崩溃报告,但是我在crashreporter文件夹中确实看到LowMemory.log。

I have upgraded my iphone and ipad to 4.2 我已将iPhone和iPad升级到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. 我的应用程序有一个名为contentViewController的根视图,用户可以从此处导航到4个测验。

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]
                                                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. 您实际上是在共享的代码中推送根视图控制器的新实例。

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

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