【发布时间】:2011-06-20 21:50:41
【问题描述】:
这里有一段代码可以突出显示屏幕的一部分,我想知道这段代码是否有任何泄漏:
- (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
【问题讨论】:
标签: iphone memory-leaks instruments