简体   繁体   English

iPhone CGPDFDocumentRef巨大的内存泄漏

[英]iphone CGPDFDocumentRef Huge memory leak

I've been doing research because my pdf viewer app keeps crashing around page 4/5 because of a memory leak that happens every time you turn a page. 我一直在进行研究,因为我的pdf查看器应用程序每次翻页时都会发生内存泄漏,因此它始终在第4/5页附近崩溃。

It turns out that apple has a bug. 事实证明,苹果有一个错误。

see here: https://devforums.apple.com/message/9077#9077 看到这里: https : //devforums.apple.com/message/9077#9077

From what I understand you have to release & retain the pdf document every time you change page. 据我了解,每次更改页面时,您都必须发布并保留pdf文档。

I can't get it to work (this code is in a subclass of UIView): 我无法正常工作(此代码在UIView的子类中):

- (void) drawInContext: (CGContextRef) ctx {
CGPDFDocumentRelease(__pdfDoc);
CGContextSetRGBFillColor( ctx, 1.0, 1.0, 1.0, 1.0 );
CGContextFillRect( ctx, CGContextGetClipBoundingBox( ctx ));
CGContextTranslateCTM( ctx, 0.0, self.bounds.size.height );
CGContextScaleCTM( ctx, 1.0, -1.0 );
CGContextConcatCTM(ctx, CGPDFPageGetDrawingTransform(pdfPage, kCGPDFCropBox, self.bounds, 0, true));
CGContextDrawPDFPage( ctx, pdfPage );NSLog(@"DONE!");
CGPDFDocumentRetain(__pdfDoc);}
@end

my pdf is opened here in a viewController: 我的pdf在viewController中打开:

- (CGPDFPageRef) pdfPage: (NSInteger) index {
if( ! __pdfDoc ) {
__pdfDoc = CGPDFDocumentCreateWithURL((CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"mybook" ofType:@"pdf"]]);}
if( __pdfDoc ) {
size_t pdfPageCount = CGPDFDocumentGetNumberOfPages( __pdfDoc );
index++;
if( index < 1 )
index = 1;
if( index > pdfPageCount )
index = pdfPageCount;
CGPDFPageRef page = CGPDFDocumentGetPage( __pdfDoc, index );
return page;}
return nil;}

I can't find anything on google and I've been reading the documentation all day. 我在Google上找不到任何东西,而且整天都在阅读文档。

Yeah. 是的 Bug. 臭虫 You will have to open/close the complete document when drawing a page. 绘制页面时,您将必须打开/关闭整个文档。 Sucks. 糟透了

(I think this is fixed in 3.2.x) (我认为这在3.2.x中已修复)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM