在iOS 8.1中,当使用CGContextDrawPDFPage将PDF页面呈现到图形上下文时,出现内存泄漏。在模拟器中不会发生这种情况,但每次我在iPad Air上都会收到数百次272字节malloc内存泄漏。如果我注释掉CGContextDrawPDFPage,泄漏就会消失。iOS 8.1中CGContextDrawPDFPage的内存泄漏?
是否有其他人获得类似的行为?
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);
这里有一个堆栈跟踪(逆转):
的malloc
38.58 MB 36.7%,148743的std :: __ 1名::列表> ::列表(STD :: __ 1 ::列表>常量&)
19.61 MB 18.6%75610的std :: __ 1 ::矢量CG ::路径::子路径CG ::分配器
19.61 MB 18.6%75610空隙的std :: __ 1 ::矢量> :: __ push_back_slow_path (CG ::路径::子路径& &)
19.61 MB 18.6%75610 CG ::路径::序列:: move_to_point(CGPoint常量&,CGAffineTransform常量*)
19.61 MB 18.6%75610 CGPathMoveToPoint
19.59 MB 18.6%75506 TTrueTypeQuadOutlineContext :: AddPoint(布尔,INT,INT)
19.59 MB 18.6%75506 TTrueTypeFontHandler :: RenderGlyph(无符号短,TTrueTypeQuadOutlineContext &,无符号整型)常量
19.59 MB 18.6%75506 TTrueTypeFontHandler :: GetOutlinePath(无符号短,TGlyphOutlineBatch常量&)常量
19.59 MB 18.6%75506 FPFontCopyGlyphPath
19.59 MB 18.6%75506 CGFontCreateGlyphPath
19.59 MB 18.6% 75506 CGFontCreateGlyphBitmap
19.59 MB 18.6%75506 CGGlyphBuilder :: create_missing_bitmaps(CGGlyphIdentifier const *,unsigned long,CGGlyphBitmap con ST **)
19.59 MB 18.6%75506个render_glyphs
19.59 MB 18.6%75506个draw_glyph_bitmaps
19.59 MB 18.6%75506个ripc_DrawGlyphs
19.59 MB 18.6%75506个draw_glyphs
19.57 MB 18.6%75434 draw_alph
19.55 MB 18.6%75359 simple_draw
19.55 MB 18.6%75359个CGPDFTextLayoutDrawGlyphs
19.55 MB 18。6%75348 op_TJ
19.55 MB 18.6%75348 pdf_scanner_handle_xname
19.55 MB 18.6%75348 CGPDFScannerScan
19.55 MB 18.6%75348 CGPDFDrawingContextDrawPage
19.55 MB 18.6%75348 pdf_page_draw_in_context
19.55 MB 18.6%75348 CGContextDrawPDFPage
您对此问题有ios8标记,并在标题中提及8.1。你能澄清一下吗?该问题是iOS 8.1还是新问题? – 2014-11-07 08:32:49
另外,你是否在autorelease池中运行这个?为了确定它不是延迟释放,可以尝试在这段代码中添加'@autoreleasepool {}'(注意,显然这会释放你最终想要传递的'image',但至少可以将其消除)。 – 2014-11-07 08:36:45
我认为它也发生在8.0中。我试过包装autorelease块没有成功。我刚刚得到了内存泄漏位置的堆栈跟踪。我会更新这个问题。 – 2014-11-07 10:21:50