[英]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.