Search code examples
iphoneobjective-cperformanceimagensbundle

Best way of loading images from application bundle


What is the best way of loading images from the application main bundle. I am using

[UIImage imageNamed: "image.png"];

But I have heard that this is not good in terms of memory usage and performance. Can anyone please give his/her feedback on it? My application reads lots of images from main bundle at launch time. I want to make this process as efficient as possible.

Best Regards


Solution

  • If you want to try loading the images without caching, you can use:

    [[UIImage alloc] initWithContentsOfFile:@"image.png"]; 
    

    This could be slightly faster loading the image for the first time, since it doesn't have to cache it first. If you only need to use these images once, it probably makes sense to try it this way. The other benefit of doing it this way is that you won't have an image cache using up memory for longer than necessary.