Low Memory Warning Prevents Image Display


I was curious about how low memory warnings impact this example. I had a bunch of apps running on my iPhone 4 (including some video editing, photo apps, and others) and ran the code to test the Image Picker for the first time. One thing I noticed is that the camera would allow me to take and use a photo; however when control returned back to my Item Detail View it did not display the chosen image.

I looked in the debug console and saw the following:

2010-11-21 12:49:41.330 Homepwner[2291:307] Using two-stage rotation animation. To use the smoother single-stage animation, this application must remove two-stage method implementations. 2010-11-21 12:49:41.333 Homepwner[2291:307] Using two-stage rotation animation is not supported when rotating more than one view controller or view controllers not the window delegate 2010-11-21 12:49:42.219 Homepwner[2291:307] Received memory warning. Level=1 2010-11-21 12:49:43.080 Homepwner[2291:307] Received memory warning. Level=2 2010-11-21 12:49:47.394 Homepwner[2291:307] Received memory warning. Level=1

When I manually forced my other apps to close - and re-ran the code - it performed exactly as expected (displaying the selected photo for all of the possessions in the list).

Taking a look at the didReceiveMemoryWarning: code, I began to wonder:

[code]- (void)didReceiveMemoryWarning {
// Releases the view if it doesn’t have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.


If I am understanding this right, the image was released as a sort of damage control, right? If this were in a production app, am I correct in thinking that here is where I would pop open an alert to the user to let them know the image was not saved - and that they should close any unnecessary apps on their iOS device to prevent against unexpected behavior?


I ran into similar issue and it was calling the didUnload. Initially it did not strike me that it has anything to do with the memory. Since I had only few applications running, I thought I am doing something wrong with my coding. I believe we need to take this into account in production environment. But the question is how we can do that. Though the try catch mechanism exists, I have not seen an argument for making use of it in Objective-C(especially in iphone apps). Maybe I should think more on how I can capture this info as in the delegate method imagePickerController:diddFinishPickingMediaWithInfo: the returned value for the key …OriginalImage was not nil while the UIImageView was becoming null. There might be a better way to identify these issues. Hope some one can shed additional light on this ?


well, chapter 15 does talk about how to handle the low memory warnings. that should address the concern raised in the first post.


I ran into this issue as well right before the ‘Creating and using keys’ section.

An explanation of what’s happening is in the following post (see the solution):

Once you complete the chapter you shouldn’t see this issue because it then handles this low memory warning: UIImageView image is populated in viewWillAppear.