[英]CGContextDrawPDFPage memory leak
Hello here is my code for drawing pdf in CATiledlayer 你好,这是我在CATiledlayer中绘制pdf的代码
- (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 这里的myPageRef是CGPDFPageRef
I had download the code from github and make some R&D and found that, 我从github下载了代码并进行了一些研发,发现,
I forgot to release CGPDFPageRelease(myPageRef)
in dealloc
method of my TiledView.. 我忘了在我的TiledView的
dealloc
方法中发布CGPDFPageRelease(myPageRef)
。
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. 在
CGContextDrawPDFPage
解决了我的类似问题之前。
Credits goes to this answer of Johann: CGContextDrawPDFPage taking up large amounts of memory 致于Johann的回答: CGContextDrawPDFPage占用了大量内存
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.