我是 ObjC 的新开发人员,正在尝试制作填充颜色应用程序。当我触摸图像时,颜色会改变,但我得到了这个功能的 merory 泄漏需要你的帮助:
-(void) updateImageWithColorSelected:(int) pos{
CGImageRef imageRef = self.basicImage.CGImage;
NSData *data = CGDataProviderCopyData(CGImagerGetDataProvider(imageRef));//leak here
Byte *pixels = (Byte *)[data bytes];
//change color...
for(int i = 0; i< IMG_SIZE; i++){
pixels[j] = 255;
}
CGDataProvider provider = CGDataProviderCreateWithData( NULL, pixels, [data length], NULL];
CGImageRef newImageRef = CGImageCreate(w,h....);
self.basicImage = [UIImage imageWithCGImage:newImageRef];
//release newImageRef
CGImagerRelease(newImageRef);
// set basic image to img
[self.img setImage:self.basicImage];
data = nil;
[data release];
}
我尝试删除除 NSData *data = CGDataProviderCopyData 之外的所有代码,并且应用程序仍然泄漏。你们知道如何发布“数据”吗?
先感谢您,
}