Question

I have read about this function didReceiveMemoryWarning that actually hasn't really helped. I would like to show a UIAlert View to tell the user that the action he is about to take will lead to problems with memory.

So apart from crashing, which is a nasty way to inform the user that there is a memory Warning received, is there a possible implementation of a UIAlertView?

Was it helpful?

Solution

In your application delegate class (eg MyApplicationAppDelegate.m) implement the didReceiveMemoryWarning method:

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{
  // Show an alert
  UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning"
                                                  message:@"Running low on memory"
                                                 delegate:nil
                                        cancelButtonTitle:@"OK"
                                        otherButtonTitles:nil];

  [alert show];
  [alert release];
}

OTHER TIPS

Pheelicks did give you a good answer to your question, but this is definetly not what you want to do. When you receive this warning, you are already in low memory condition. What you want to do when you receive this warning is release as much memory as possible. Like large images that you might be keeping in memory, large arrays of string or any other large object. Instruments will help you alot in finding the culprits.

Also, you also want to implement didReceiveMemoryWarning on any view controller that allocates alot of memory so they can do some cleanin up there also

Hopes this helps :)

the action he is about to take will lead to problems with memory

If there is some action you know of the user taking that will lead to memory problems, you should keep them from taking that action, or just warn them yourself when they are about to take the action (with an alertview).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top