【问题标题】:iphone CGPDFDocumentRef Huge memory leakiphone CGPDFDocumentRef 巨大的内存泄漏
【发布时间】:2010-08-23 19:41:25
【问题描述】:

我一直在做研究,因为每次翻页时都会发生内存泄漏,我的 pdf 查看器应用程序在第 4/5 页左右不断崩溃。

原来苹果有bug。

请看这里:https://devforums.apple.com/message/9077#9077

据我了解,每次更改页面时,您都必须发布并保留 pdf 文档。

我无法让它工作(这段代码在 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

我的 pdf 在 vi​​ewController 中打开:

- (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;}

我在谷歌上找不到任何东西,我整天都在阅读文档。

【问题讨论】:

    标签: ios cgpdfdocument


    【解决方案1】:

    是的。漏洞。绘制页面时,您必须打开/关闭整个文档。糟透了。

    (我认为这在 3.2.x 中已修复)

    【讨论】:

    • 我要下载 sdk 4.0 我会告诉你问题是否已修复
    • 哇——这是最近的帖子吗?但你可能是对的。 Afaik 没有 Create:s 等可以在绘制页面时指示页面的所有权 - 我猜想逐页绘制时的所有内存都“挂在”原始文档引用上(其中确实包括单词 Create、CGPDFDocumentCreateWithURL,这将表明所有权)?无论如何,如果您从未获得不再需要的页面的唯一所有权,您将如何释放它们的内存?
    猜你喜欢
    • 2018-01-19
    • 2010-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-02
    • 2014-02-10
    • 2013-05-15
    相关资源
    最近更新 更多