CGContextDrawPDFPage内存泄漏

时间:2011-03-08 11:08:00

标签: 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));
         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

2 个答案:

答案 0 :(得分:5)

我从github下载了代码并制作了一些R& D并发现了

我忘了在我的TiledView的CGPDFPageRelease(myPageRef)方法中发布dealloc ..

写完这段代码后,我的内存泄漏就解决了......

 // Clean up.

 - (void)dealloc {
     CGPDFPageRelease(myPageRef);   
     [super dealloc];
 }

答案 1 :(得分:3)

致电

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

之前CGContextDrawPDFPage解决了我的类似问题。

致于约翰恩的回答: CGContextDrawPDFPage taking up large amounts of memory

相关问题