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
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];
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With