Reputation: 40349
First: I've implement a fairly complex scrolling mechanism for images, that allows to scroll over a few hundred thousands (theoretically) in one single scroll view. This is done by preloading small portions upon scrolling, while re-using all UIImageViews. Currently all I do is to assign new created UIImage objects to those re-used UIImageViews.
It might be better if it's possible to also re-use those UIImage objects by passing new image data to them.
Now the problem is, that I am currently using the -imageNamed: method. The documentation says, that it caches the image.
Problems I see in this case with -imageNamed: As the image gets scrolled out of the preloading range, it's not needed anymore. It would be bad if it tries to cache thousands of images while the user scrolls and scrolls and scrolls. And if I would find a way to stuff new image data into the UIImage object for re-using it, then what happens with the old image that was cached?
So there is one method left, that seems interesting: -initWithContentsOfFile:
This does not cache the image. And it doesn't use -autorelease, which is good in this case.
Do you think that in this case it would be better to use -initWithContentsOfFile:?
Upvotes: 1
Views: 986
Reputation: 1878
I found one link regarding this which comments of imageNamed method http://www.alexcurylo.com/blog/2009/01/13/imagenamed-is-evil/
Upvotes: 0
Reputation: 6697
I'd say YES. You have too much images to keep all of them in cache so you can't use -imageNamed:. If your images are not displayed many times, you will not get lower performance.
Upvotes: 0
Reputation: 54110
Only a benchmark can tell you for sure. I'm inclined to think that UIImage
image caching is probably extremely efficient, given that it's used virtually everywhere in the OS. That said with the number of images you're displaying, your approach might help.
Upvotes: 2