Memory Leak iOS (UIImageView,UIImage,CGImage) not freed on ARC

Im trying to implement a simple video stream but for some reason my memory won't get 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]);

memory will be freed. But when I return to a previous view controller the app will crash as it tries to free the allocated memory for that image, which I already freed. This method is called from a async task which creates an image using:

UIImage *image = [UIImage imageWithCGImage:cgImage];

As I understood it the UIImage now owns the CGImage and I shouldn't have to release it. So is there anyway to ensure that the UIImage is freed when I updated the UIImageView with a new image?


Ok so I finally figured out the problem.

As I said I was using some background thread to perform the image update, the solution was to add it as a autorelease pool as following:

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

Need Your Help

How safe are “secret” keys in Windows 8 (WinJs) apps?

security windows-8 winjs code-access-security secret-key

I'm doing a hobby project Windows 8 app in WinJS. As I'm calling an external api, which requires an api key and oauth authentication, I've got a number of keys that I need to keep "secret".

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.