I am getting errors of type EXC-BAD-ACCESS where I create a new UIImage instance by assigning the value of a pre-existing UIImage (as below) and I am trying to figure out what the problem is. There is a heap of code to sort through and I am not sure where to start so I won’t bother posting source — but it might help me in my investigation of any of you could tell me What exactly is going on (memory-wise) when I create a new UIImage by assigning from another?
(in the .h)
UIImage* myExistsImage;
...
@property (retain) UIImage* myExistsImage;
...
-(UIImage*)rotateImage:(UIImage*)imageToRotate;
----------------------------------------------------
(in the .m)
@synthesize myExistsImage;
...
UIImage* myNewImage = [self rotateImage:myExistsImage];
...
-(UIImage*)rotateImage:(UIImage*)imageToRotate
{
UIImage* rotatedImage = imageToRotate;
//Rotate Image Here (details omitted)...
return rotatedImage;
}
In that line, you’re not creating a new UIImage object; you’re simply creating a new pointer to the old one. If
Rotate Image Hereimplies in-place modifications torotatedImage, then you’re actually modifyingmyExistsImageas well.If you want to create a new UIImage object to hold the rotated object, you’ll need to explicitly do so with the UIImage
allocandinitmethods.