title: [iOS]Does Image I/O cache decoded image when creating image source with CFDataRef?
body: <p>I know I can create UIImages  with <code>[UIImage imageNamed:]</code> or other <code>UIImage</code> methods. I use Image I/O to create gif animation in my app. And resize images too since it's super fast! </p>
  
  <p>In WWDC 2012 session: <a href="https://developer.apple.com/videos/wwdc/2012/" rel="nofollow" title="iOS App Performance: Graphics and Animations">iOS App Performance: Graphics and Animations</a> , Apple engineer suggests that I shouldn't cache images myself because image caching is handled by system. From Apple's <a href="https://developer.apple.com/library/ios/documentation/graphicsimaging/conceptual/ImageIOGuide/imageio_basics/ikpg_basics.html#//apple_ref/doc/uid/TP40005462-CH216-TPXREF101" rel="nofollow">Image I/O Programming Guide</a> , one of features Image I/O provides is </p>
  
  <blockquote>
    <p>Effective caching</p>
  </blockquote>
  
  <p>So I decided let Image I/O cache all images for me. There is a key named <code>kCGImageSourceShouldCache</code> in 
  <code>Image Source Option Dictionary Keys</code> of which the description says</p>
  
  <blockquote>
    <p>Whether the image should be cached in a decoded form. </p>
  </blockquote>
  
  <p>I believe if I create an image source with an url, then the images created later are cached. But what if the image source is created with a <code>CFDataRef</code> object? It's just a pointer to some image data, it's not like an url which can identify a unique resource. Does Image I/O still cache images in this case? Thanks.</p>
  
  <p>Here is the code I used to create image:</p>
  
  <pre><code>CFDictionaryRef   myOptions = NULL;
  CFStringRef       myKeys[2];
  CFTypeRef         myValues[2];
  
  myKeys[0] = kCGImageSourceShouldCache;
  myValues[0] = (CFTypeRef)kCFBooleanTrue;
  myKeys[1] = kCGImageSourceShouldAllowFloat;
  myValues[1] = (CFTypeRef)kCFBooleanTrue;
  
  myOptions = CFDictionaryCreate(NULL, (const void **) myKeys,
                                 (const void **) myValues, 2,
                                 &amp;kCFTypeDictionaryKeyCallBacks,
                                 &amp; kCFTypeDictionaryValueCallBacks);
  
  CGImageSourceRef imageSource = CGImageSourceCreateWithData(imageData, myOptions);
  CFRelease(myOptions);
  CGImageRef myImage = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL);
  CFRelease(imageSource);
  </code></pre>