Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CGContextDrawPDFPage memory leak

Tags:

ios

ipad

Hello here is my code for drawing pdf in CATiledlayer

- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
{

         CGContextSetRGBFillColor(ctx, 1.0, 1.0, 1.0, 1.0);
         CGContextFillRect(ctx, CGContextGetClipBoundingBox(ctx));
         CGContextTranslateCTM(ctx, 0.0, layer.bounds.size.height);
         CGContextScaleCTM(ctx, 1.0, -1.0);
         CGContextConcatCTM(ctx, CGPDFPageGetDrawingTransform(myPageRef, kCGPDFCropBox, layer.bounds, 0, true));
         CGContextDrawPDFPage(ctx, myPageRef);
 }

All is well but i got memory leak warning in following line

     CGContextDrawPDFPage(ctx, myPageRef);

Here myPageRef is CGPDFPageRef

like image 624
Mehul Mistri Avatar asked Mar 08 '11 11:03

Mehul Mistri


2 Answers

I had download the code from github and make some R&D and found that,

I forgot to release CGPDFPageRelease(myPageRef) in dealloc method of my TiledView..

and after writing this code my memory leak solved....

 // Clean up.

 - (void)dealloc {
     CGPDFPageRelease(myPageRef);   
     [super dealloc];
 }
like image 103
Mehul Mistri Avatar answered Oct 18 '22 21:10

Mehul Mistri


Calling

CGContextSetInterpolationQuality(context, kCGInterpolationHigh); 
CGContextSetRenderingIntent(context, kCGRenderingIntentDefault);

before CGContextDrawPDFPage solved a similar problem of mine.

Credits goes to this answer of Johann: CGContextDrawPDFPage taking up large amounts of memory

like image 41
aslisabanci Avatar answered Oct 18 '22 20:10

aslisabanci