UIImage return nil on some images?

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

Answers


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.


Need Your Help

Lifetime issue when implementing Iterator

iterator rust lifetime

I was implementing the Iterator trait for several structs and encountered some problems. Why is implementing Iterator for Rows shows error?

Why does MLLib GenerateLinearInput internally multiply variance by 12.0?

random apache-spark mllib

Consider the generateLinearInput method from MLLib LinearDataGenerator:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.