2011-02-03 44 views
0

下面是一段代碼,以突出屏幕的一部分,我想知道是否有這個代碼的任何泄漏:儀表不顯示任何泄漏,但撥款不斷增加

- (UIImage*)createImageSection:(UIImage*)image section:(CGRect)section 
{ 
UIScreen *screen = [UIScreen mainScreen]; 
float originalWidth = image.size.width * [screen scale] ; 
float originalHeight = image.size.height * [screen scale]; 
int w = originalWidth * section.size.width ; 
int h = originalHeight * section.size.height ; 


CGContextRef ctx = CGBitmapContextCreate(nil, w , h , 8, w * 8, CGImageGetColorSpace([image CGImage]), kCGImageAlphaPremultipliedLast); 
CGContextClearRect(ctx, CGRectMake(0, 0, originalWidth * section.size.width * [screen scale], originalHeight * section.size.height * [screen scale])); // w + h before 
CGContextTranslateCTM(ctx, (float)-originalWidth * section.origin.x , (float)-originalHeight * section.origin.y); 
CGContextDrawImage(ctx, CGRectMake(0, 0, originalWidth , originalHeight), [image CGImage]); 

CGImageRef cgImage = CGBitmapContextCreateImage(ctx); 
//UIImage* resultImage = [[UIImage alloc] initWithCGImage:cgImage scale: [screen scale]]; 
UIImage* resultImage = [[UIImage alloc] initWithCGImage:cgImage scale:[screen scale] orientation:UIImageOrientationUp] ; 
CGContextRelease(ctx); 
CGImageRelease(cgImage); 
return resultImage ; 

}

感謝 DKV

回答

-1

自動釋放resultImage

UIImage* resultImage = [[UIImage alloc] initWithCGImage:cgImage scale:[screen scale] orientation:UIImageOrientationUp] 

UIImage* resultImage = [[[UIImage alloc] initWithCGImage:cgImage scale:[screen scale] orientation:UIImageOrientationUp] autorelease]; 
+0

-1:方法定義中有'創建'。每次調用create,new或alloc方法時,要遵循Apple的指導原則,您有責任釋放該對象,不會返回自動釋放的對象。 – v1Axvw 2011-02-03 20:11:35

相關問題