[英]Memory Leak in CGContextDrawPDFPage in iOS 8.1?
Under iOS 8.1 I'm getting a memory leak when rendering a PDF page into a graphics context with CGContextDrawPDFPage. 在iOS 8.1下,当使用CGContextDrawPDFPage将PDF页面渲染到图形上下文时,我遇到内存泄漏。 It doesn't happen in the simulator but I get hundreds of leaks of 272 bytes of malloc'd memory every time I do it (on iPad Air).
它不会发生在模拟器中,但每次我都会在iPad Air上获得数百个272字节的malloc内存泄漏。 If I comment out the CGContextDrawPDFPage the leak goes away.
如果我注释掉CGContextDrawPDFPage,泄漏就会消失。
Does anyone else get similar behaviour? 有没有其他人得到类似的行为?
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);
Here's a stack trace (reversed): 这是一个堆栈跟踪(反向):
malloc 的malloc
38.58 MB 36.7% 148743 std::__1::list >::list(std::__1::list > const&) 38.58 MB 36.7%148743 std :: __ 1 :: list> :: list(std :: __ 1 :: list> const&)
19.61 MB 18.6% 75610 std::__1::vector CG::Path::Subpath CG::Allocator 19.61 MB 18.6%75610 std :: __ 1 :: vector CG :: Path :: Subpath CG :: Allocator
19.61 MB 18.6% 75610 void std::__1::vector >::__push_back_slow_path(CG::Path::Subpath&&) 19.61 MB 18.6%75610 void std :: __ 1 :: vector> :: __ push_back_slow_path(CG :: Path :: Subpath &&)
19.61 MB 18.6% 75610 CG::Path::Sequence::move_to_point(CGPoint const&, CGAffineTransform const*) 19.61 MB 18.6%75610 CG :: Path :: Sequence :: move_to_point(CGPoint const&,CGAffineTransform const *)
19.61 MB 18.6% 75610 CGPathMoveToPoint 19.61 MB 18.6%75610 CGPathMoveToPoint
19.59 MB 18.6% 75506 TTrueTypeQuadOutlineContext::AddPoint(bool, int, int) 19.59 MB 18.6%75506 TTrueTypeQuadOutlineContext :: AddPoint(bool,int,int)
19.59 MB 18.6% 75506 TTrueTypeFontHandler::RenderGlyph(unsigned short, TTrueTypeQuadOutlineContext&, unsigned int) const 19.59 MB 18.6%75506 TTrueTypeFontHandler :: RenderGlyph(unsigned short,TTrueTypeQuadOutlineContext&,unsigned int)const
19.59 MB 18.6% 75506 TTrueTypeFontHandler::GetOutlinePath(unsigned short, TGlyphOutlineBatch const&) const 19.59 MB 18.6%75506 TTrueTypeFontHandler :: GetOutlinePath(unsigned short,TGlyphOutlineBatch const&)const
19.59 MB 18.6% 75506 FPFontCopyGlyphPath 19.59 MB 18.6%75506 FPFontCopyGlyphPath
19.59 MB 18.6% 75506 CGFontCreateGlyphPath 19.59 MB 18.6%75506 CGFontCreateGlyphPath
19.59 MB 18.6% 75506 CGFontCreateGlyphBitmap 19.59 MB 18.6%75506 CGFontCreateGlyphBitmap
19.59 MB 18.6% 75506 CGGlyphBuilder::create_missing_bitmaps(CGGlyphIdentifier const*, unsigned long, CGGlyphBitmap const**) 19.59 MB 18.6%75506 CGGlyphBuilder :: create_missing_bitmaps(CGGlyphIdentifier const *,unsigned long,CGGlyphBitmap const **)
19.59 MB 18.6% 75506 render_glyphs 19.59 MB 18.6%75506 render_glyphs
19.59 MB 18.6% 75506 draw_glyph_bitmaps 19.59 MB 18.6%75506 draw_glyph_bitmaps
19.59 MB 18.6% 75506 ripc_DrawGlyphs 19.59 MB 18.6%75506 ripc_DrawGlyphs
19.59 MB 18.6% 75506 draw_glyphs 19.59 MB 18.6%75506 draw_glyphs
19.57 MB 18.6% 75434 draw_glyphs 19.57 MB 18.6%75434 draw_glyphs
19.55 MB 18.6% 75359 simple_draw 19.55 MB 18.6%75359 simple_draw
19.55 MB 18.6% 75359 CGPDFTextLayoutDrawGlyphs 19.55 MB 18.6%75359 CGPDFTextLayoutDrawGlyphs
19.55 MB 18.6% 75348 op_TJ 19.55 MB 18.6%75348 op_TJ
19.55 MB 18.6% 75348 pdf_scanner_handle_xname 19.55 MB 18.6%75348 pdf_scanner_handle_xname
19.55 MB 18.6% 75348 CGPDFScannerScan 19.55 MB 18.6%75348 CGPDFScannerScan
19.55 MB 18.6% 75348 CGPDFDrawingContextDrawPage 19.55 MB 18.6%75348 CGPDFDrawingContextDrawPage
19.55 MB 18.6% 75348 pdf_page_draw_in_context 19.55 MB 18.6%75348 pdf_page_draw_in_context
19.55 MB 18.6% 75348 CGContextDrawPDFPage 19.55 MB 18.6%75348 CGContextDrawPDFPage
Yes, you need to call UIGraphicsEndImageContext()
to match every call to UIGraphicsBeginImageContext()
. 是的,您需要调用
UIGraphicsEndImageContext()
来匹配对UIGraphicsBeginImageContext()
每个调用。
Per the UIKit framework reference : 根据UIKit框架参考 :
When you are done modifying the context, you must call the
UIGraphicsEndImageContext
function to clean up the bitmap drawing environment and remove the graphics context from the top of the context stack.完成上下文修改后,必须调用
UIGraphicsEndImageContext
函数来清理位图绘制环境,并从上下文堆栈顶部删除图形上下文。 You should not use theUIGraphicsPopContext
function to remove this type of context from the stack.您不应该使用
UIGraphicsPopContext
函数从堆栈中删除此类上下文。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.