Reputation: 3444
I have about 500 images as resources in my app.
First, is that a bad thing? How else can I store them?
Second, when I load them as follows:
for (int i=0; i < [imageArray count]; i ++)
{
IngredientObject * o = ((ImageObject*)[imageArray objectAtIndex:i]);
UIImage * img = [UIImage imageNamed:o.imageName];
.
.
.
}
Sometime it returns nil. I am assuming it is a memory issue since it does not happen on the simulator, only on the real device. Each image is small... about 10k to 20k each, but that still ends up being about 10meg. I did not think this would be a problem on a 16gb device.
Would it be better to not use imageNamed: and use imageWithContentsOfFile or some other method. This images are ultimately in a UIScrollerView and I am not sure how I would go about loading them as needed because I was concerned about the scrolling performance if it had to load the images dynamically.
Any help is appreciated.
Thank you
Upvotes: 0
Views: 752
Reputation: 50697
It's not necessarily a bad thing to have 500+ images, as long as you handle your memory management correctly. In my experience, imageWithCOntentsOfFile:
seems to be alot faster than imageNamed:
.
As far as the UIScrollView
performance, again, handling only a few images at a time will ensure that your scrolling isn't delayed or jerky.
As far as 10MG vs. 16GB device, that is totally irrelevant. iPhone 3GS has about 128MB's of FREE MEMORY; iPhone 4 has somewhere around 300MB's+ roughly depending on what you have running in the background.
It seems like you are trying to load all 500 images into the ScrollView, this would be the reason your are getting empty images which results in low memory.
Upvotes: 1