Ian
Ian

Reputation: 1

iphone app crashes due to Low Memory but works fine in simulator

Dear all, I have a navigation-based app with about 60 UIControllerViews, which is divided into 4 sections.

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. 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.

Is there a need to remove/release the UIControllerViews? The app crashes simply by navigating between the views.

Thank you for any help.

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]; 
}
else {
}

}

Upvotes: 0

Views: 1809

Answers (4)

Supamodz
Supamodz

Reputation: 36

You are using up memory, always remember if you allocate memory you must release it, in some cases you can use autorelease so you dont forget to release it after the void dealloc method before end.

Upvotes: 0

David Frantz
David Frantz

Reputation: 51

You have some good suggestions already. However I'd suggest spending a lot of time reviewing XCode's debugging tools documentation. This so you have a basic understanding of what they are capable of and how to use them. Follow that up with some reading on iOS memory management, auto release pools and the like.

For your app you need to realize that there is no swap space on iOS devices. So you are forced to manage memory to an extent that you mat not have to on other platforms. Generally that means you don't want to keep to much view data in memory if it can be avoided.

In the case of the current iPad there may only be about 110MB of RAM available to the app. Specific numbers probably are iOS version dependent. In any event you need to get an idea as to how large the data structures (in memory) are for your various views. 60 different views could be considered a lot depending upon memory usage, if you don't manage it correctly you are likely to run out very quickly. This not like programming in Java or other garbage collected language.

Lastly; even though this sounds like a memory management issue it could always be something else. If you still have trouble you will need to post code. Right now it is really guess work on our part. Just remember you do not have VM and there is no garbage collection.

Upvotes: 0

Noah Witherspoon
Noah Witherspoon

Reputation: 57149

The simulator isn't going to give you any useful information about memory warnings—your app, running there, effectively has access to all the memory the system's willing to give it. The device is where you need to be testing for memory usage, and if you're getting warnings and crashes, then you need to do some Instruments work to figure out where you can free up some of that memory.

Upvotes: 3

Kenny Winker
Kenny Winker

Reputation: 12107

Look at your xcode console. If you are getting a number of low memory warnings, then you need to be allocating and de-allocating your views on the fly because they are taking up too much memory on the device (the simulator isn't quite so memory restricted).

But it could be about a million other things causing your crash. Make sure you're doing a debug build (breakpoints on) so the debugger will kick in and hopefully you can see where on the stack your crash is occurring.

Upvotes: 1

Related Questions