I didn't notice much performance lost by doing this. So I wonder if it doesn't hurt when I re-use the same UIImage multiple times at the same time inside multiple UIImageViews?
views:
88answers:
1
+1
A:
OK, I haven't profiled this, but... It shouldn't consume more memory. When you use a UIImageView, what happens is the CALayer that provides the visual appearance of all UIView subclasses on the iPhone, has it's content property set to a CGImage object. When you set up multiple UIImageView objects with the same image, Cocoa Touch is smart enough to use the same CGImage as the content property for each UIImageView's CALayer.
You do have multiple UIImageViews and each has it's own CALayer, but when a CALayer is just displaying an unchanging image (one loaded from a file or URL), it's a very lightweight object.
U62
2009-07-18 09:12:54
Great explanation! Would it matter if the UIImageViews are animated and transformed?
Thanks
2009-07-18 10:13:17
If you mean animating the position or transform of the UIImageView, then no, it doesn't matter as long as the UIImageView is initialized with the same image file.
U62
2009-07-19 11:00:49