首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CGContextDrawPDFPage在iOS 8.1中的内存泄漏?

CGContextDrawPDFPage在iOS 8.1中的内存泄漏?
EN

Stack Overflow用户
提问于 2014-11-06 15:41:55
回答 1查看 907关注 0票数 5

在iOS 8.1下,当使用CGContextDrawPDFPage将一个PDF页面呈现到图形上下文中时,我会发现内存泄漏。在模拟器中没有发生这种情况,但是每次我这样做(在iPad Air上),我都会得到272个字节的malloc内存泄漏。如果我评论一下CGContextDrawPDFPage,泄漏就消失了。

其他人也有类似的行为吗?

代码语言:javascript
复制
CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData((CFDataRef)data);
CGPDFDocumentRef pdf = CGPDFDocumentCreateWithProvider(dataProvider);


CGPDFPageRef page;

// Grab the PDF page
page = CGPDFDocumentGetPage(pdf, pageNo + 1);

UIGraphicsBeginImageContext(aRect.size);
CGContextRef context = UIGraphicsGetCurrentContext();

CGContextTranslateCTM(context, 0, aRect.size.height);
CGContextScaleCTM(context, 1, -1);

CGContextDrawPDFPage(context, page); // <-  LEAKING?!?!?

// Would create the new UIImage from the context
//image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

CGPDFDocumentRelease(pdf);
CGDataProviderRelease(dataProvider);

下面是堆栈跟踪(反向):

马洛

38.58MB 36.7% 148743 std::__1::list >:list(std::__1::list> const&)

19.61MB 18.6% 75610 std::__1::vector CG::Path::子路径CG::分配器

19.61MB 18.6% 75610 std::__1::vector >::__push_back_slow_path(CG::Path::Subpath&)

19.61MB 18.6% 75610 CG::Path::Sequence::move_to_point(CGPoint const&,CGAffineTransform const*)

19.61MB 18.6% 75610 CGPathMoveToPoint

19.59 MB 18.6% 75506 TTrueTypeQuadOutlineContext:AddPoint(bool,int,int)

19.59 MB 18.6% 75506 TTrueTypeFontHandler:RenderGlyph(未签名短,TTrueTypeQuadOutlineContext&,未签名int)

19.59 MB 18.6% 75506 TTrueTypeFontHandler::GetOutlinePath(无符号短,TGlyphOutlineBatch const&)

19.59MB 18.6% 75506 FPFontCopyGlyphPath

19.59MB 18.6% 75506 CGFontCreateGlyphPath

19.59MB 18.6% 75506 CGFontCreateGlyphBitmap

19.59 MB 18.6% 75506 CGGlyphBuilder::create_missing_bitmaps(CGGlyphIdentifier const*,未签名CGGlyphBitmap const**)

19.59MB 18.6% 75506 render_glyphs

19.59MB 18.6% 75506 draw_glyph_bitmaps

19.59MB 18.6% 75506 ripc_DrawGlyphs

19.59MB 18.6% 75506 draw_glyphs

19.57MB 18.6% 75434 draw_glyphs

19.55MB 18.6% 75359 simple_draw

19.55MB 18.6% 75359 CGPDFTextLayoutDrawGlyphs

19.55MB 18.6% 75348 op_TJ

19.55MB 18.6% 75348 pdf_scanner_handle_xname

19.55MB 18.6% 75348 CGPDFScannerScan

19.55MB 18.6% 75348 CGPDFDrawingContextDrawPage

19.55MB 18.6% 75348 pdf_page_draw_in_context

19.55MB 18.6% 75348 CGContextDrawPDFPage

EN

回答 1

Stack Overflow用户

发布于 2014-11-07 06:12:00

是的,您需要调用UIGraphicsEndImageContext()来匹配对UIGraphicsBeginImageContext()的每个调用。

根据UIKit框架参考

修改完上下文后,必须调用UIGraphicsEndImageContext函数来清理位图绘制环境,并从上下文堆栈顶部删除图形上下文。您不应该使用UIGraphicsPopContext函数从堆栈中删除这种类型的上下文。

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

https://stackoverflow.com/questions/26783443

复制
相关文章

相似问题

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