Search code examples
iphoneiosipadcgimage

Won't run with CFRelease but zombies with out it


In this code:

            url = [NSURL fileURLWithPath:t.exportedFullName];

            myImageDest = CGImageDestinationCreateWithURL((CFURLRef)url, (CFStringRef)t.asset.defaultRepresentation.UTI, 1, nil);

            if(!myImageDest) {
                NSLog(@"***Could not create image destination ***");
            }
            inImage = t.asset.defaultRepresentation.fullResolutionImage;

            CGImageDestinationAddImage(myImageDest, inImage, (CFDictionaryRef)t.freshMetaData);
            success = CGImageDestinationFinalize(myImageDest);
            if(!success)
                NSLog(@"***Could not create data from image destination ***");

            [url release];
            CGImageRelease(inImage);
            CFRelease(myImageDest);

Which runs in a loop loopping through an array of image information (t) if I don't use the CFRelease(myImageDest); I get low memory warnings and the app eventually dies (when running on the device).

If I use it I get:

-[Not A Type _cfTypeID]: message sent to deallocated instance

and profiling with Zombies in instruments shows [UIImage dealloc] with a refcnt of -1 and on the line just above it shows CFRelease with a refcnt of 0 in this class above. The CFRelease shown is the only one in the class.

Can't live with it, can't live without...makin' me crazy...

Any ideas?


Solution

  • The offending line is:

     CGImageRelease(inImage);
    

    This shouldn't be needed because defaultRepresentation.fullResolutionImage does not increase the retain count of the returned CGImage.

    Also, [url release] is not needed for the same reason.