Take the 2-minute tour ×

I'm trying to find ways to cut down memory usage for my app right now, and I have an idea regarding UIImages. I make pretty extensive usage of UIImages, some of them common to multiple views. Is it a lot more memory efficient to instantiate a single UIImage and then use a pointer to that same image throughout the app rather than allocating a new UIImage for the same image in each view? Or, is the OS smart enough to sort of automatically cache a UIImage so that it is only stored in memory once? (doubt that's the case but I have to ask)


share|improve this question

4 Answers 4

up vote 3 down vote accepted

Straight from UIImage apple reference docs for imageNamed:


share|improve this answer
Always a good idea to check the documentation first, but thanks for the response, this definitely answers my question. –  Rich Byden Nov 26 '11 at 0:33

You use a lot of images, so remember that [UIImage imageNamed:@""]; caches the images, so if you are having low memory problem use instead [UIImage imageWithContentsOfFile:@""]; that doesn't cache it. Maybe that can help you cut down memory usage.

share|improve this answer
This wouldn't lower his memory issue. In fact, it would increase it, as he uses the same image over and over. Constantly adding a new image into memory every time he reuses would be the exact thing he wants to avoid. –  ColdLogic Nov 25 '11 at 21:10

When a view unloads set the GUI properties to nil in the viewDidUnload method of UIViewController subclasses.

share|improve this answer

Yes, it is more efficient to store a single UIImage and use pointers to it.

It is unlikely that the OS caches images in this way, and even if it did, using pointers gives you more fine control of when the image is released / deallocated so that you don't have to hope the OS is going to take care of it.

share|improve this answer
However, if you're using less than hundreds of copies of UIImages, you may not have to worry much about memory here - it may be more beneficial to have simpler code and use more duplicates than to create very complicated code which only saves a few hundred bytes of RAM. (Especially when it comes to debugging down the road...) –  Tim Gostony Nov 25 '11 at 20:42
imageNamed: caches images on first load and then reuses the cached image any subsequent attempt to load. –  ColdLogic Nov 25 '11 at 21:05
Oh, thank you. I did not know this! –  Tim Gostony Nov 26 '11 at 21:21

Your Answer


