Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: CGPDFPageRef memory leak
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CGPDFPageRef memory leak



File a bug (with a minimal test case), mark it as a dupe of
rdar://problem/6367689, and join the club :(

H

On Wed, Apr 7, 2010 at 7:51 PM, Carlo Eugster <email@hidden> wrote:
> Hi,
> Does anyone have an idea why this code would leak memory? The method is used
> to flip through the pages of the PDF document, but something along the line
> does not seem to be released properly. I narrowed the problem down to this
> chunk of code since the footprint of my application shoots up drastically
> whenever I pull a page that has graphics on it. It's been driving me crazy
> for the past several days, so any help would be greatly appreciated!
>
> -(UIImage *)pageAtIndex:(NSInteger)pageNumber withWidth:(CGFloat)width
> andHeight:(CGFloat)height {
>
> if((pageNumber>0) && (pageNumber<=pageCount)) {
>
> CGFloat scaleRatio; // multiplier by which the PDF Page will be scaled
>
> UIGraphicsBeginImageContext(CGSizeMake(width, height));
>
> CGContextRef context = UIGraphicsGetCurrentContext();
>
> CGPDFPageRef page = CGPDFDocumentGetPage(pdf, pageNumber);
>
> CGRect pageRect = CGPDFPageGetBoxRect(page, kCGPDFBleedBox);
>
> //Figure out the orientation of the PDF page and set the scaleRatio
> accordingly
>
> if(pageRect.size.width/pageRect.size.height < 1.0) {
>
> scaleRatio = height/pageRect.size.height;
>
> }
>
> else {
>
> scaleRatio = width/pageRect.size.width;
>
> }
>
> //Calculate the offset to center the image
>
> CGFloat xOffset = 0.0;
>
> CGFloat yOffset = height;
>
> if(pageRect.size.width*scaleRatio<width) {
>
> xOffset = (width/2)-(pageRect.size.width*scaleRatio/2);
>
> }
>
> else {
>
> yOffset = height-((height/2)-(pageRect.size.height*scaleRatio/2));
>
> }
>
> CGContextTranslateCTM(context, xOffset, yOffset);
>
> CGContextScaleCTM(context, 1.0, -1.0);
>
> CGContextSaveGState(context);
>
> CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page,
> kCGPDFBleedBox, CGRectMake(0, 0, pageRect.size.width, pageRect.size.height),
> 0, true);
>
> pdfTransform = CGAffineTransformScale(pdfTransform, scaleRatio, scaleRatio);
>
> CGContextConcatCTM(context, pdfTransform);
>
> CGContextDrawPDFPage(context, page);
>
> UIImage *tempImage = UIGraphicsGetImageFromCurrentImageContext();
>
> CGContextRestoreGState(context);
>
> UIGraphicsEndPDFContext();
>
> UIGraphicsEndImageContext();
>
> return tempImage;
>
> }
>
> return nil;
>
> }
>
> Carlo
>  _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Quartz-dev mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartz-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >CGPDFPageRef memory leak (From: Carlo Eugster <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.