views:

316

answers:

2

Hi there,

I need to use a stretchable UIImage hundreds of times in my app in multiple UIImageViews. Is it okay to globally reuse the same stretchable UIImage instead of having to recreate them in memory each time I need to add it to a UIImageView?

I know [UIImage imageNamed:] caches images for better performance, but this cannot be used for stretchable images!

Thanks,

Mike

+1  A: 

Definitely: Reuse your image. Are you storing it in a global variable? Make sure you retain the image (or put it in a retained property fo some global class like your Application) since it probably came AutoReleased.

Rob Fonseca-Ensor
Thanks for your help as well, I accepted the first response as the answer only because it was first and you can't except multiple answers!!
Michael Waterfall
+2  A: 

Oh, absolutely, you should always store your image once and then call that same image every time you want to draw it. Typically for projects with a lot of images I have a single SpriteManager class that contains an NSDictionary full of sprites. Then I can reference each one via filename. This way each image is loaded only once, which is significantly faster.

The absolutely most efficient way to do this, though, is just to use OpenGL ES. And if you've got hundreds of images being drawn, I absolutely recommend that you do so.

Eli