Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CGImageSourceRef memoryleak

NSDictionary* result = nil;

CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)[self TIFFRepresentation], NULL);

if ( NULL == source )
{
}
else
{
    CFDictionaryRef metadataRef = CGImageSourceCopyPropertiesAtIndex (source, 0, NULL);
    if (metadataRef)
    {
        NSDictionary* immutableMetadata = (__bridge NSDictionary *)metadataRef;
        if (immutableMetadata)
        {
            result = [NSDictionary dictionaryWithDictionary : (__bridge NSDictionary *)metadataRef];
        }

        CFRelease(metadataRef);
        metadataRef = nil;
    }

    CFRelease(source);
    source = nil;
}

return result;

I am using XCode with ARC. This code causes my app to leak memory when i run it on many images in a loop. Does anybody know what i did wrong?

like image 275
Tuan Avatar asked Apr 29 '26 23:04

Tuan


1 Answers

wrapping @autoreleasepool around code solved the problem. Images were about 1.2MB

like image 103
Tuan Avatar answered May 02 '26 00:05

Tuan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!