Ios CGContextDrawPDFPage内存泄漏
您好,这是我在CATiledlayer中绘制pdf的代码Ios CGContextDrawPDFPage内存泄漏,ios,ipad,Ios,Ipad,您好,这是我在CATiledlayer中绘制pdf的代码 - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx { CGContextSetRGBFillColor(ctx, 1.0, 1.0, 1.0, 1.0); CGContextFillRect(ctx, CGContextGetClipBoundingBox(ctx)); CGContextTranslateC
- (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);
}
一切都很好,但我得到了内存泄漏警告在下面的一行
CGContextDrawPDFPage(ctx, myPageRef);
这里的myPageRef是CGPDFPageRef我从github下载了代码并进行了一些研发,发现 我忘记在我的平铺视图的
dealoc
方法中发布cgpdfagerelease(myPageRef)
写了这段代码后,我的内存泄漏得到了解决
// Clean up.
- (void)dealloc {
CGPDFPageRelease(myPageRef);
[super dealloc];
}
召唤
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
CGContextSetRenderingIntent(context, kCGRenderingIntentDefault);
之前,CGContextDrawPDFPage
解决了我的一个类似问题
约翰的回答是:
只有在某个时候保留它时,才应该这样做。但如果您只是在执行
CGPDFDocumentGetPage
,则会得到一个autorelease对象,因此不应释放它。(显然,如果您保留了它,那么您当然必须按照此答案中的建议释放它)。