在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