0
任何一个可以解决我的问题在下面的代码中的内存泄漏?UIImage内存泄漏
-(void)paint:(ImageWarper::WarpedImage *)warpedImg isCircleRequired:(bool)doDrawCircle atPoint:(CGPoint)pt{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
if(!mWarper)
return;
unsigned char *pixelData = warpedImg->Image.Data;
int imageHeight = warpedImg->Image.Height;
int scanWidth = warpedImg->Image.ScanWidth;
int imageWidth = warpedImg->Image.Width;
CGDataProviderRef provider = CGDataProviderCreateWithData(
NULL,
pixelData,
imageHeight * scanWidth,
NULL);
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
int bytesPerPixel = warpedImg->Image.Bpp;
CGImageRef imageRef = CGImageCreate(imageWidth,
imageHeight,
BitsPerComponent,
bytesPerPixel * BitsPerComponent,
scanWidth,
colorSpaceRef,
bitmapInfo,
provider,
NULL,
YES,
renderingIntent);
UIImage *uiImage = [UIImage imageWithCGImage:imageRef];
CGColorSpaceRelease(colorSpaceRef);
CGDataProviderRelease(provider);
// CGColorSpaceRelease(colorSpaceRef);
CGImageRelease(imageRef);
imgScrollView.imgView.image = uiImage;
UIGraphicsBeginImageContext(mbmpImage.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(ctx, 1.5);
CGContextSetStrokeColorWithColor(ctx, [UIColor whiteColor].CGColor);
[mbmpImage drawInRect:CGRectMake(0, 0, mbmpImage.size.width, mbmpImage.size.height)];
[uiImage drawInRect:CGRectMake(warpedImg->Position.X, warpedImg->Position.Y, warpedImg->Image.Width, warpedImg->Image.Height)];
[mbmpImage release];
mbmpImage = [UIGraphicsGetImageFromCurrentImageContext() retain];
if(doDrawCircle){
mbmpImage = [UIGraphicsGetImageFromCurrentImageContext() retain];
CGContextStrokeEllipseInRect(ctx,CGRectMake(pt.x - mRadius, pt.y - mRadius, mRadius*2, mRadius*2));
}
UIImage * resultingImage = [UIGraphicsGetImageFromCurrentImageContext() retain];
UIGraphicsEndImageContext();
imgScrollView.imgView.image = resultingImage ;
if(!doDrawCircle)
mbmpImage = [resultingImage retain];
[resultingImage release];
[pool drain];
}
该功能被称为触摸事件..
这是仪器的卡在那里它表明泄漏..
也许你只是传递保留消息,并将这些值给予mbmpImage,但从不释放mbmpImage ...尝试正确释放它。 – mayuur
mbmpImage是类变量,我使用它在每个地方 – DivineDesert
那么你应该释放该变量dealloc部分或保持它在autorelease模式。 – mayuur