2011-02-03 40 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

相关问题