title: UIImage from CGImageRef
body: <p>I am trying a simple test for a much more complex project but I am baffled as to why the code below is crashing and giving an EXC_BAD_ACCESS error? </p>
  
  <p>This is called from a UIView.</p>
  
  <pre><code> - (void)testing {
        NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"ball.png" ofType:nil];
        CGImageRef imageRef = [[[UIImage alloc]initWithContentsOfFile:imagePath]CGImage];
   //   CGImageRetain(imageRef);
  
        UIImage *newImage = [[UIImage alloc]initWithCGImage:imageRef];
        UIImageView *iv = [[UIImageView alloc]initWithImage:newImage];
        [self addSubview:iv];
   }
  </code></pre>
  
  <p>My guess is that the CGImageRef is not being retained but adding CGImageRetain(imageRef); makes no difference.</p>
  
  <p>I should also note that this project has ARC turned on.</p>
  
  <p><strong><em></strong> EDIT <strong></em></strong></p>
  
  <p>I did a little bit more testing and have discovered that this is directly related to ARC as I created 2 basic projects including only the code above. The first with ARC turned off and it worked perfectly. The next with ARC turned on and BAM crash with the same error. The interesting thing is that I got an actual log error ONLY the first time I ran the project before the crash.</p>
  
  <pre><code> Error: ImageIO: ImageProviderCopyImageBlockSetCallback 'ImageProviderCopyImageBlockSetCallback' header is not a CFDictionary...
  </code></pre>