I would like to handle out of memory errors in iPhone to execute logic with lesser memory requirements in case I run of of memory. In particular, I would like to do something very similar to the following pseudo-code:
UIImage* image;
try {
image = [UIImage imageNamed:@"high_quality_image.png"];
} catch (OutOfMemoryException e) {
image = [UIImage imageNamed:@"low_quality_image.jpg"];
}
First I attempt to load a high-quality image, and if I run out of memory while doing it, then I use a lower quality image.
Would this be possible? Is there some kind of exception or notification than can be handled when an out of memory error occurs?
The out of memory warning is not what I'm looking for, as it's received before the phone runs out of memory. I would like to know if the logic I'm executing failed because an out of memory error, and deal with this accordingly.
Alternatively, something like this could also help:
UIImage* image;
if (enoughMemory) {
image = [UIImage imageNamed:@"high_quality_image.png"];
} else {
image = [UIImage imageNamed:@"low_quality_image.jpg"];
}