Search code examples
iosuitableviewimage-caching

Image caching in iOS


If I do

rowBackground = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"bottomCell2.png"] 

the image is cached for the entire life cycle of the app or reloaded and recached everytime I execute that instruction (in other views or part of the app)?

I do that in every tableview of my app. Is it efficient?

Thanks in advance!


Solution

  • As the reference of +imageNamed::

    This method looks in the system caches for an image object with the specified name and returns that object if it exists. If a matching image object is not already in the cache, this method loads the image data from the specified file, caches it, and then returns the resulting object.

    Cache is efficient, but eats memory. If your table view contains large amount of images, the memory may burn up. So you may consider +imageWithContentsOfFile: or other similar methods to load image.