Skip to content

Instantly share code, notes, and snippets.

Last active December 6, 2019 18:58
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ccgus/b810c80f0c246d7587cb141bd3f8c216 to your computer and use it in GitHub Desktop.
Asking the internet for help to make sure I'm not being stupid.
This sample shows how CGImageSourceCreateThumbnailAtIndex leaks something akin
to the memory behind a CGImageRef when asked to create a thumbnail for a 16bpc
TIFF image if one isn't present.
Full sample project here:
void report_memory(void) {
struct task_basic_info info;
mach_msg_type_number_t size = sizeof(info);
kern_return_t kerr = task_info(mach_task_self(),
if( kerr == KERN_SUCCESS ) {
NSLog(@"Used memory (in mb): %f", (double)info.resident_size / 1024.0 / 1024.0);
} else {
NSLog(@"Error with task_info(): %s", mach_error_string(kerr));
- (void)loadThumbnailsForImageWithName:(NSString *)name {
@autoreleasepool {
NSLog(@"Loading image %@", name);
NSURL *sixteenURL = [[NSBundle mainBundle] URLForImageResource:name];
CGImageSourceRef imageSourceRef = CGImageSourceCreateWithURL((CFURLRef)sixteenURL, nil);
for (int i = 0; i < 500; i++) {
CGImageRef r = CGImageSourceCreateThumbnailAtIndex(imageSourceRef, 0, (CFDictionaryRef)@{(id)kCGImageSourceCreateThumbnailFromImageIfAbsent: @(YES), (id)kCGImageSourceThumbnailMaxPixelSize:@(256), (id)kCGImageSourceCreateThumbnailWithTransform: @(YES)});
NSLog(@"Finished with image %@", name);
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[self loadThumbnailsForImageWithName:@"EightBit"];
[self loadThumbnailsForImageWithName:@"SixteenBit"];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment