title: Core Graphics memory leaks while displaying pdf images
body: <p>I have a subclass of UIImageView view that loads pdf image data, so that I can have a resolution independent graphic in my view. Works well for the stated purpose, but I am getting memory leaks with this, according to an instruments leaks profile. </p>
  
  <p>Here is the code below that I believe should be responsible for the leaks. I am trying to track down the problem, but I am a little foggy on how to pinpoint the issue. </p>
  
  <pre><code>- (id)initWithPDFResourceAtPath:(NSString *)path center:(CGPoint)center {
      if ((self = [super init])){
          CGPDFPageRelease(pageRef);
          CGPDFDocumentRef documentRef = CGPDFDocumentCreateWithURL((__bridge CFURLRef)[NSURL fileURLWithPath:path]);
          pageRef = CGPDFDocumentGetPage(documentRef, 1);
          CGPDFPageRetain(pageRef);
          CGPDFDocumentRelease(documentRef);
          [self setBounds];
      }
      return self;
  }
  
  -(void)setBounds {
      [self setBounds:CGRectApplyAffineTransform(CGPDFPageGetBoxRect(pageRef, kCGPDFMediaBox), CGAffineTransformMakeScale(scaleH, scaleV))];
      size = self.bounds.size;
      [self getPDFimage];
  }
  
  -(void)getPDFimage {
      UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
      CGContextRef context = UIGraphicsGetCurrentContext();
      CGContextScaleCTM(context, scaleH, scaleV);
      CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
      CGContextSetRenderingIntent(context, kCGRenderingIntentDefault);
      CGContextDrawPDFPage(context, pageRef);
      [self setImage:UIGraphicsGetImageFromCurrentImageContext()];
  }
  </code></pre>