1

There is a conflict between the docs and the header file regarding the default value of kCGImageSourceShouldCache. They say the precise opposite. Obviously the workaround is to set the value explicitly, but it would be useful to know the true default behaviour for working on legacy code.

The docs say:

kCGImageSourceShouldCache

Whether the image should be cached in a decoded form. The value of this key must be a CFBoolean value. The default value is kCFBooleanTrue in 32-bit, kCFBooleanFalse in 64-bit. This key can be provided in the options dictionary that you can pass to the functions CGImageSourceCopyPropertiesAtIndex and CGImageSourceCreateImageAtIndex.

Available in iOS 4.0 and later.

Declared in CGImageSource.h.

The header file says:

/* Specifies whether the image should be cached in a decoded form. The
 * value of this key must be a CFBooleanRef.
 * kCFBooleanFalse indicates no caching, kCFBooleanTrue indicates caching.
 * For 64-bit architectures, the default is kCFBooleanTrue, for 32-bit the default is   kCFBooleanFalse.
 */

IMAGEIO_EXTERN const CFStringRef kCGImageSourceShouldCache      
IMAGEIO_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_4_0);
Airsource Ltd
  • 32,379
  • 13
  • 71
  • 75
  • Now [the doc says](https://developer.apple.com/documentation/imageio/kcgimagesourceshouldcache?language=objc) "The default value is kCFBooleanFalse in 32-bit, kCFBooleanTrue in 64-bit". – Pang Aug 10 '17 at 10:43

1 Answers1

1

Just to add to the confusion, I ran a test on iOS and checked the memory usage following this code with a very large image

    NSDictionary *options = [NSDictionary dictionaryWithObjects:@[@(4096),  @(YES), @(YES)] forKeys:
                         @[(id)kCGImageSourceThumbnailMaxPixelSize,
                           (id)kCGImageSourceCreateThumbnailWithTransform,
                           (id)kCGImageSourceCreateThumbnailFromImageIfAbsent]];

    CGImageRef thumbnail = CGImageSourceCreateThumbnailAtIndex(myImageSource, 0,(__bridge CFDictionaryRef) options);

The results showed that the default value of kCGImageSourceShouldCache is NO on both 32 and 64 bit (memory usage was much higher following this code when I manually set the value to YES).

Airsource Ltd
  • 32,379
  • 13
  • 71
  • 75