Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios CGContextDrawPDFPage内存泄漏_Ios_Ipad - Fatal编程技术网

Ios CGContextDrawPDFPage内存泄漏

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

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

我从github下载了代码并进行了一些研发,发现

我忘记在我的平铺视图的
dealoc
方法中发布
cgpdfagerelease(myPageRef)

写了这段代码后,我的内存泄漏得到了解决

 // Clean up.

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

CGContextSetInterpolationQuality(context, kCGInterpolationHigh); 
CGContextSetRenderingIntent(context, kCGRenderingIntentDefault);
之前,
CGContextDrawPDFPage
解决了我的一个类似问题

约翰的回答是:

只有在某个时候保留它时,才应该这样做。但如果您只是在执行
CGPDFDocumentGetPage
,则会得到一个autorelease对象,因此不应释放它。(显然,如果您保留了它,那么您当然必须按照此答案中的建议释放它)。