【问题标题】:CGContextDrawPDFPage memory leakCGContextDrawPDFPage 内存泄漏
【发布时间】:2011-03-08 11:08:00
【问题描述】:

你好,这是我在 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

【问题讨论】:

    标签: ios ipad


    【解决方案1】:

    我从github下载了代码,做了一些研发,发现,

    我忘记在我的 TiledView 的 dealloc 方法中释放 CGPDFPageRelease(myPageRef)..

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

     // Clean up.
    
     - (void)dealloc {
         CGPDFPageRelease(myPageRef);   
         [super dealloc];
     }
    

    【讨论】:

    • 只有在某个时候保留它时才应该这样做。但是如果你只是在做CGPDFDocumentGetPage,你会得到一个自动释放对象,因此你不应该释放它。 (显然,如果您保留它,那么您当然必须按照此答案中的建议释放它)。
    【解决方案2】:

    打电话

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

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

    归功于约翰的这个答案: CGContextDrawPDFPage taking up large amounts of memory

    【讨论】:

      猜你喜欢
      • 2015-01-03
      • 2018-04-04
      • 2012-12-17
      • 1970-01-01
      • 1970-01-01
      • 2011-12-30
      • 2011-10-08
      • 2013-01-20
      • 2011-10-31
      相关资源
      最近更新 更多