Where does the d instance get released?
Ahh, hmm. It was being released down the page somewhere, but as it turns out I didn't need that retain at all. Good catch. But that wasn't enough, I also need to dealloc the
incoming image when I'm done with it. So I threw a release in the image processing method:
+(UIImage)testMethod:(UIImage)img
{
NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
float w=img.size.width;
float h=img.size.height;
CGRect imgRec=CGRectMake(0, 0, w, h);
UIGraphicsBeginImageContextWithOptions(img.size ,YES, 1.0); //Create a context (freed below)
//CGContextRef ctxt = UIGraphicsGetCurrentContext(); //Get reference to the context
[img drawInRect:imgRec]; //Draw existing image into context
[img release]; //<<<<---- ADDED THIS RELEASE.. BUT THIS ISN'T GOOD PRACTICE?
UIImage *resultImg=UIGraphicsGetImageFromCurrentImageContext(); //This is autoreleased according to UIKit docs
[resultImg retain]; //Retain this image since we will drain the pool
UIGraphicsEndImageContext(); //Destroy the context we created earlier
//CGContextRelease(ctxt); // Crashes if we try to also explicitely release the context.. So it must be deallocing with above line.
[pool drain];
[resultImg autorelease];
return resultImg;
}
I don't believe this is good form because the method is releasing something it didn't retain/create. But I don't see how else to do it where I can control exactly when the "incoming" image is released.. Autoreleasing from the 'higher' level won't do it..