iPhone 应用程序由于内存不足而崩溃,但在模拟器中运行良好

标签 iphone memory crash

亲爱的,我有一个基于导航的应用程序,大约有 60 个 View 。

我运行了以下内容:
1.构建和分析:构建成功,没有提示。
2.仪器分配和泄漏:没有泄漏。

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

我已将我的 iphone 和 ipad 升级到 4.2

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

谢谢大家的回复。

我的应用程序有一个名为 contentViewController 的 Root View ,用户可以从这里导航到 4 个测验。

这是我用来返回 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]; 
}

}

推送 View 的示例代码:
-(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];   

}

最佳答案

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

然而,模拟器确实有一个功能,您可以手动触发内存不足事件。如果这实际上是设备崩溃的原因,那么您也有可能以这种方式在模拟器中触发相同的错误。

关于iPhone 应用程序由于内存不足而崩溃,但在模拟器中运行良好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4275323/

相关文章:

c - 如何将字符串添加到C中的字符串数组

android - 在没有错误日志的情况下 react native 应用程序崩溃,如何检测错误?

iphone - dismissModalViewControllerAnimated使我的应用程序崩溃:(

iphone - 带有动画和 View 管理的 removeFromSuperview

ios - 无法访问设置 -> 开发人员

tomcat - 检测 Web 应用程序中的内存泄漏

Xcode 9.3 在 SourceEditorDataSource.insertTextAtPosition 中崩溃

iphone - 我可以在设置 viewController 时跳过创建单独的指针吗?

c++ - 尝试在 iPhone 应用程序中使用 C++

java - 堆外、 native 堆、直接内存和 native 内存有什么区别?