我知道这个问题已经问过好几次了,但我无法解决我的特殊情况。CGContextDrawPDFPage被表示为泄漏仪器中的泄漏。另外,当运行这段代码时,应用程序崩溃,我确信这是由于内存问题造成的。
pdfURLDocument = [[NSURL alloc] initFileURLWithPath: [docsDir stringByAppendingPathComponent:documentName]];
pdfDocument = CGPDFDocumentCreateWithURL((CFURLRef)pdfURLDocument);
[pdfURLDocument release];
page = CGPDFDocumentGetPage(pdfDocument, 1);
CGPDFPageRetain(page);
// determine the size of the PDF page
CGRect pageRect = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
pdfScaleWidth = (1/((CGFloat) gridSizeDocument)) * self.frame.size.width/pageRect.size.width;
pdfScaleHeight = (1/((CGFloat) gridSizeDocument)) * self.frame.size.height/pageRect.size.height;
pageRect.size = CGSizeMake(pageRect.size.width*pdfScaleWidth, pageRect.size.height*pdfScaleHeight);
// Create a low res image representation of the PDF page
UIGraphicsBeginImageContext(pageRect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
// First fill the background with white.
CGContextSetRGBFillColor(context, 1.0,1.0,1.0,1.0);
CGContextFillRect(context,pageRect);
CGContextSaveGState(context);
// Flip the context so that the PDF page is rendered
// right side up.
CGContextTranslateCTM(context, 0.0, pageRect.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
// Scale the context so that the PDF page is rendered
// at the correct size for the zoom level.
CGContextScaleCTM(context, pdfScaleWidth, pdfScaleHeight);
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
CGContextSetRenderingIntent(context, kCGRenderingIntentDefault);
CGContextDrawPDFPage(context, page);
CGContextRestoreGState(context);
backgroundImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGPDFPageRelease(page);此外,我还在dealloc方法中包括了CGPDFPageRelease(page);。此外,它可能有助于补充说,它可以很好地工作小型文档,但只崩溃的大型文档。然而,内存泄漏仍然存在于较小的内存泄漏中。
发布于 2013-07-17 13:27:28
我知道这是个老问题,但有两点意见:
pdfDocument:但是,CGPDFDocumentRelease(pdfDocument);
CGPDFPageRelease(page)发布page,因为这是一个自动释放的对象,并且您不拥有它(当然,除非您在CGPDFPageRetain中保留了它)。如果您使用静态分析器(Xcode的“产品”菜单上的“分析”),它应该指出这两个问题。
根本的问题是CGContextDrawPDFPage在6.0之前的iOS版本中泄漏。
发布于 2012-05-01 10:38:17
发行版需要在页面被使用后发布,而不是之前。因此,首先,将CGPDFPageRelease(page)移动到这个代码块中,看看这是否有帮助。而且,这个问题可能与存储在CGPDFDocumentRef变量中的pdf有关。如果上面的内容没有帮助,那么如果您展示如何获得引用,以及您保留和释放它的位置,那将是很好的。
https://stackoverflow.com/questions/10395017
复制相似问题