kCGImageSourceShouldCache的默认值是多少?

时间:2014-08-27 10:11:07

标签: ios macos core-graphics 32bit-64bit

关于kCGImageSourceShouldCache的默认值,docs和头文件之间存在冲突。他们说恰恰相反。显然,解决方法是显式设置值,但了解处理遗留代码的真正默认行为会很有用。

文档说:

kCGImageSourceShouldCache

图像是否应以解码形式缓存。此键的值必须是CFBoolean值。默认值为32位的kCFBooleanTrue,64位的kCFBooleanFalse。可以在选项字典中提供此密钥,您可以将其传递给函数CGImageSourceCopyPropertiesAtIndex和CGImageSourceCreateImageAtIndex。

适用于iOS 4.0及更高版本。

在CGImageSource.h中声明。

标题文件显示:

/* 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);

1 个答案:

答案 0 :(得分:0)

只是为了增加混乱,我在iOS上运行测试,并使用非常大的图像检查此代码后的内存使用情况

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

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

结果显示kCGImageSourceShouldCache的默认值在32位和64位都是NO(当我手动将值设置为YES时,此代码后的内存使用率要高得多)。