Rohan
Rohan

Reputation: 23

UIImage release error - *** -[UIImage release]: message sent to deallocated instance

I have come up with an error "* -[UIImage release]: message sent to deallocated instance". Here is what I am doing.

void imageFromPicture(AVPicture *pict, int width, int height)
{
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
CFDataRef data = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, pict->data[0], pict->linesize[0]*height,kCFAllocatorNull);
CGDataProviderRef provider = CGDataProviderCreateWithCFData(data);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGImageRef cgImage = CGImageCreate( width, 
                            height, 
                            8, 
                            24, 
                            pict->linesize[0], 
                            colorSpace, 
                            bitmapInfo, 
                            provider, 
                            NULL, 
                            NO, 
                            kCGRenderingIntentDefault);
CGColorSpaceRelease(colorSpace);
UIImage *image = [UIImage imageWithCGImage:cgImage];
CGImageRelease(cgImage);
CGDataProviderRelease(provider);
CFRelease(data);

[ref_to_self display: image];
[image release];
}

- (void) display:(UIImage*)image
{
self.ImageView.image = image;
}

Now, the function imageFromPicture is being called continuously in an infinite loop, until some break condition. This is used to display a continuous sequence of images. This code works properly, but after all my images are displayed and the control returns back to the Operating System I get this error.

Can somebody please tell me what wrong am I doing. I do not have much idea on objective C memory management.

Upvotes: 0

Views: 1680

Answers (1)

jtbandes
jtbandes

Reputation: 118671

This line

UIImage *image = [UIImage imageWithCGImage:cgImage];

returns an autoreleased object, so this line

[image release];

is unnecessary and invalid.

Upvotes: 1

Related Questions