你好,這裏是我在CATiledlayer繪製PDF的代碼CGContextDrawPDFPage內存泄露
- (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
你應該只能做,如果你保留它在某個時候。但是如果你只是在做'CGPDFDocumentGetPage',你會得到一個autorelease對象,因此你不應該釋放它。 (顯然,如果你保留它,那麼當然你必須按照這個答案中的建議釋放它)。 – Rob 2013-07-17 14:07:15
https://stackoverflow.com/questions/46903182/cgcontextdrawpdfpage-memory-leak-app-crash – Ravindhiran 2017-10-24 06:26:49