我正在使用此功能裁剪图像,当我使用它时,它不会释放内存,我尝试不使用它,并且内存工作正常。我似乎找不到它的问题。请帮助

- (void) processImage:(UIImage *)image {
haveImage = YES;

UIGraphicsBeginImageContext(image.size);
[image drawInRect: CGRectMake(0, 0, image.size.width, image.size.height)];


__weak UIImage *smallImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

CGRect cropRect = CGRectMake(0, 0, image.size.width, image.size.height - ((image.size.height - image.size.width)/2));
CGImageRef imageRef = CGImageCreateWithImageInRect([smallImage CGImage], cropRect);

__weak UIImage *corteSuperior =[UIImage imageWithCGImage:imageRef];

cropRect = CGRectMake(0, ((image.size.height - image.size.width)/2), corteSuperior.size.width, corteSuperior.size.height - ((image.size.height - image.size.width)/2));
imageRef = CGImageCreateWithImageInRect([corteSuperior CGImage], cropRect);



 self.imagenCamara.image = [UIImage imageWithCGImage:imageRef];



smallImage = nil;
imageRef = nil;
corteSuperior = nil;

UIGraphicsEndImageContext();
CGImageRelease(imageRef);

}

最佳答案

您必须为每个CGImageRelease呼叫呼叫CGImageCreateWithImageInRect呼叫。您永远不会释放第一次出现的情况。第二次分配imageRef之前,请释放第一个imageRef

另外,最后,请确保先执行CGImageRelease,然后再nil imageRef指针。通过将imageRef设置为nil,您将失去对imageRef的引用,因此CGImageRelease将无法释放任何内容。

关于ios - 我创建IOS 7的功能出现内存问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21702045/

10-09 08:54