I am trying to implement a simple video stream, but for some reason my memory will not be freed:
(void)updateImage:(UIImage *)image{
self.indicator.hidden = TRUE;
self.imageView.image = nil;
self.imageView.image = image;
[self.imageView setNeedsDisplay];
}
If i use
CGImageRelease([self.imageView.image CGImage]);
the memory will be freed. But when I return to the previous view controller, the application crashes, trying to free the allocated memory for this image, which I have already freed. This method is called from an async task that creates an image using:
UIImage *image = [UIImage imageWithCGImage:cgImage];
CGImageRelease(cgImage);
CGDataProviderRelease(provider);
CFRelease(data);
As I understand it, UIImage now owns CGImage, and I do not need to release it. Anyway, to ensure that the UIImage is freed when I update the UIImageView with a new image?