IOS memory leak (UIImageView, UIImage, CGImage) not released on ARC

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;
  //CGImageRelease([self.imageView.image CGImage]);
  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?

+3
1

, , , .

, , , :

   @autoreleasepool {
        [self.delegate performSelectorOnMainThread:@selector(updateImage:) withObject:[self fetchImage] waitUntilDone:NO];
    }
+5

Source: https://habr.com/ru/post/1525500/


All Articles