在我的應用程序中,我有一個循環,在UIImage
陣列上移動,並使這個圖像的東西。 在後臺線程循環工作,以便在函數的開始,我把:[游泳池釋放];崩潰我的應用程序
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
,並最終
[pool release];
在循環中我創建UIImage
,所以我需要釋放它,因爲它給我一個記憶警告,如果我沒有發佈。
當應用程序完成的循環,並獲得了
[pool release];
它給我BAD_ACCESS
錯誤和崩潰的應用程序。
編輯
這是循環
UIImage *tmp = [image rotate:UIImageOrientationRight];
//do some stuff with this image
[tmp release];
這是rotate方法的方法:
UIImage* copy = nil;
CGRect bnds = CGRectZero;
UIImage* copy = nil;
CGContextRef ctxt = nil;
CGImageRef imag = self.CGImage;
CGRect rect = CGRectZero;
CGAffineTransform tran = CGAffineTransformIdentity;
rect.size.width = CGImageGetWidth(imag);
rect.size.height = CGImageGetHeight(imag);
bnds = rect;
UIGraphicsBeginImageContext(bnds.size);
ctxt = UIGraphicsGetCurrentContext();
switch (orient)
{
case UIImageOrientationLeft:
case UIImageOrientationLeftMirrored:
case UIImageOrientationRight:
case UIImageOrientationRightMirrored:
CGContextScaleCTM(ctxt, -1.0, 1.0);
CGContextTranslateCTM(ctxt, -rect.size.height, 0.0);
break;
default:
CGContextScaleCTM(ctxt, 1.0, -1.0);
CGContextTranslateCTM(ctxt, 0.0, -rect.size.height);
break;
}
CGContextConcatCTM(ctxt, tran);
CGContextDrawImage(UIGraphicsGetCurrentContext(), rect, imag);
copy = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
if (imag) {
CFRelease(imag);
}
return copy;
你可以發表代碼如何初始化你的UIImage? –
我編輯我的文章的代碼 – MTA
是的,當你耗盡從池創建以來已經被自動釋放的所有內容的池。這可能會導致兩個問題:1)釋放已釋放的內容 - 通常會導致出現此錯誤消息。 2)發佈真正需要的東西,比如你的一個UI對象。這通常會導致一個非常無用的崩潰消息。有時候,具體原因相當明顯,其他時候確實是一個挑戰。 –