Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><a href="http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIImage_Class/Reference/Reference.html#//apple_ref/occ/clm/UIImage/imageNamed:" rel="noreferrer">The documentation says:</a></p> <blockquote> <p>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.</p> </blockquote> <p>Thus, every image you load by using <code>imageNamed:</code> will continue to exist in the cache after you release your last ownership of it.</p> <p>Instruments doesn't show this as a leak because, strictly speaking, it isn't one: Something (UIImage) still knows about these images. The Leaks instrument will only show a leak for an object that exists but nothing knows about.</p> <p>You can still see this in Instruments, though.</p> <ol> <li>Select the ObjectAlloc instrument in your trace document and sort the list of classes by current count, or by current total size. You'll see that the bulk of the memory is occupied by UIImage objects.</li> <li>If you mouse over the class-name column for the UIImage row, you'll see a ➲ (go-to-iTunes-Store) icon; if you click on that, you'll see a list of all of your UIImage instances.</li> <li><p>Then, if you mouse over the address column for an instance's row, you'll see the same button; this time, clicking on it will take you to the history of that address, including all creations, retentions, releases, and deallocations of objects with that address.</p> <p>Here, you can see the image's allocation (within the UIImage class, ordered by you a few stack-frames down), retention (by you), and release (by you). You can also see that it has not been released by UIImage—the <code>+[UIImage imageNamed:]</code> cache still owns the image, hence the “leak”.</p></li> </ol> <p>If you don't want images to pile up like that, load them yourself using <code>imageWithContentsOfFile:</code> and <a href="http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSBundle_Class/Reference/Reference.html#//apple_ref/occ/instm/NSBundle/pathForResource:ofType:" rel="noreferrer">the <code>-[NSBundle pathForResource:ofType:]</code> method</a>.</p> <p><strong>UPDATE:</strong> I have read that since iOS 3, UIImage will purge its cache in (at least some) low-memory situations, so this should not be as much of a “leak” as it used to be. You'll probably still see memory pile up, but then you should see the pile collapse eventually. If you still see memory piling up and can prove that it's Apple's fault, you should document your evidence and <a href="https://bugreport.apple.com/" rel="noreferrer">file a bug</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload