title: Memory Leak in CGContextDrawPDFPage in iOS 8.1?
body: <p>Under iOS 8.1 I'm getting a memory leak when rendering a PDF page into a graphics context with CGContextDrawPDFPage.  It doesn't happen in the simulator but I get hundreds of leaks of 272 bytes of malloc'd memory every time I do it (on iPad Air).  If I comment out the CGContextDrawPDFPage the leak goes away.</p>
  
  <p>Does anyone else get similar behaviour?  </p>
  
  <pre><code>CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData((CFDataRef)data);
  CGPDFDocumentRef pdf = CGPDFDocumentCreateWithProvider(dataProvider);
  
  
  CGPDFPageRef page;
  
  // Grab the PDF page
  page = CGPDFDocumentGetPage(pdf, pageNo + 1);
  
  UIGraphicsBeginImageContext(aRect.size);
  CGContextRef context = UIGraphicsGetCurrentContext();
  
  CGContextTranslateCTM(context, 0, aRect.size.height);
  CGContextScaleCTM(context, 1, -1);
  
  CGContextDrawPDFPage(context, page); // &lt;-  LEAKING?!?!?
  
  // Would create the new UIImage from the context
  //image = UIGraphicsGetImageFromCurrentImageContext();
  
  UIGraphicsEndImageContext();
  
  CGPDFDocumentRelease(pdf);
  CGDataProviderRelease(dataProvider);
  </code></pre>
  
  <p>Here's a stack trace (reversed):</p>
  
  <p>malloc</p>
  
  <p>38.58 MB      36.7% 148743        std::__1::list >::list(std::__1::list > const&amp;)</p>
  
  <p>19.61 MB      18.6% 75610          std::__1::vector CG::Path::Subpath CG::Allocator </p>
  
  <p>19.61 MB      18.6% 75610           void std::__1::vector >::__push_back_slow_path(CG::Path::Subpath&amp;&amp;)</p>
  
  <p>19.61 MB      18.6% 75610            CG::Path::Sequence::move_to_point(CGPoint const&amp;, CGAffineTransform const*)</p>
  
  <p>19.61 MB      18.6% 75610             CGPathMoveToPoint</p>
  
  <p>19.59 MB      18.6% 75506              TTrueTypeQuadOutlineContext::AddPoint(bool, int, int)</p>
  
  <p>19.59 MB      18.6% 75506               TTrueTypeFontHandler::RenderGlyph(unsigned short, TTrueTypeQuadOutlineContext&amp;, unsigned int) const</p>
  
  <p>19.59 MB      18.6% 75506                TTrueTypeFontHandler::GetOutlinePath(unsigned short, TGlyphOutlineBatch const&amp;) const</p>
  
  <p>19.59 MB      18.6% 75506                 FPFontCopyGlyphPath</p>
  
  <p>19.59 MB      18.6% 75506                  CGFontCreateGlyphPath</p>
  
  <p>19.59 MB      18.6% 75506                   CGFontCreateGlyphBitmap</p>
  
  <p>19.59 MB      18.6% 75506                    CGGlyphBuilder::create_missing_bitmaps(CGGlyphIdentifier const*, unsigned long, CGGlyphBitmap const**)</p>
  
  <p>19.59 MB      18.6% 75506                     render_glyphs</p>
  
  <p>19.59 MB      18.6% 75506                      draw_glyph_bitmaps</p>
  
  <p>19.59 MB      18.6% 75506                       ripc_DrawGlyphs</p>
  
  <p>19.59 MB      18.6% 75506                        draw_glyphs</p>
  
  <p>19.57 MB      18.6% 75434                         draw_glyphs</p>
  
  <p>19.55 MB      18.6% 75359                          simple_draw</p>
  
  <p>19.55 MB      18.6% 75359                           CGPDFTextLayoutDrawGlyphs</p>
  
  <p>19.55 MB      18.6% 75348                            op_TJ</p>
  
  <p>19.55 MB      18.6% 75348                             pdf_scanner_handle_xname</p>
  
  <p>19.55 MB      18.6% 75348                              CGPDFScannerScan</p>
  
  <p>19.55 MB      18.6% 75348                               CGPDFDrawingContextDrawPage</p>
  
  <p>19.55 MB      18.6% 75348                                pdf_page_draw_in_context</p>
  
  <p>19.55 MB      18.6% 75348                                 CGContextDrawPDFPage</p>