views:

227

answers:

2

According to the UIImage documentation:

In low-memory situations, image data may be purged from a UIImage object to free up memory on the system.

Does anyone know how this works? It appears that this process is completely transparent and will occur in the background with no input from me, but I can't find any definitive documentation one way or the other.

Second, will this data-purge occur when the image is not loaded by me? (I'm getting the image from UIImagePicker).

Here's the situation: I'm taking a picture with the UIImagePickerController and and immediately taking that image and sending it to a new UIViewController for display. Sending the raw image to the new controller crashes my app with memory warnings about 30% of the time. Resizing the image takes a few moments, time that I'd rather not spend if there's a 3rd option available to me.

A: 

In answer to your second question: Save it to a file, and then use:

[NSData dataWithContentsOfMappedFile:]

to do the resizing. Using a files as intermediates, is rather slow though.

Alfons
+1  A: 

I think this is the answer. In the documentation for initWithContentsOfFile: it says:

This method loads the image data into memory and marks it as purgeable. If the data is purged and needs to be reloaded, the image object loads that data again from the specified path.

None of the other methods in UIImage mention purging, so it appears that initializing a new image from a file is the only way to get this low memory behavior.

kubi