首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iphone CGPDFDocumentRef大内存泄漏

iphone CGPDFDocumentRef大内存泄漏
EN

Stack Overflow用户
提问于 2010-08-23 19:41:25
回答 1查看 1.5K关注 0票数 0

我一直在做研究,因为我的pdf查看程序一直在4/5页附近崩溃,因为每次你翻一个页面时都会发生内存泄漏。

结果发现苹果有个窃听器。

见此处:https://devforums.apple.com/message/9077#9077

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

我无法让它工作(这段代码位于UIView的子类中):

代码语言:javascript
复制
- (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是在这里打开在一个viewController:

代码语言:javascript
复制
- (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;}

我在google上找不到任何东西,我已经阅读了一整天的文档。

EN

回答 1

Stack Overflow用户

发布于 2010-08-23 20:51:39

嗯。虫子。绘制页面时,必须打开/关闭完整的文档。烂透了。

(我认为这是在3.2.x中修正的)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3551076

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档