0
votes

I'm getting an EXC_BAD_ACCESS when releasing newImage on the last line of the following code snippet:

UIGraphicsBeginImageContext(newSize);
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

[self setImageToSave:newImage];
[newImage release];

I'm assuming that newImage is released with the call on the preceding line. If so, why is it being released in the setImageToSave method?

1

1 Answers

4
votes

Looks like this line:

UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

is creating an autoreleased object. In between that line and before this line:

[newImage release];

..it is getting autoreleased. You're trying to release an autoreleased (and already released) object is why you're getting that error. Remove the release. As for this line:

[self setImageToSave:newImage];

If you need to save newImage for any release you should retain either here or in the setImageToSave method. Remember, since you manually retained it you'll need to match it with a release at some point either within the same method or somewhere else.