Memory leak in CGContextDrawPDFPage
| Originator: | lievendekeyser | ||
| Number: | rdar://28415289 | Date Originated: | 22-Sep-2016 |
| Status: | Open | Resolved: | |
| Product: | iOS SDK | Product Version: | iOS 10.0 (14A5339a) |
| Classification: | Reproducible: | Always |
Summary:
Every time a PDF page is drawn in a CGContextRef, a copy of its resources (images in the PDF etc) are created and retained (probably by the context).
In our app we use a CATiledLayer to draw PDFs, which seems to trigger this bug, probably because CATiledLayer uses a pool of CGContextRefs that it reuses when needed. I tried to find a workaround but couldn't find a way to drain that pool.
Steps to Reproduce:
Profile the attached project using the Allocations Instrument
Watch memory usage go up
(see ViewController.m for relevant code)
Expected Results:
Memory usage should only go up during CGContextDrawPDFPage, but then go down immediately, or at least after CGPDFDocumentRelease
Actual Results:
Memory usage goes up with every iteration
Multiple copies of a 7.77MB image are kept in memory
Version:
iOS 10
Notes:
Configuration:
iPad Mini 2, iPhone SE, iOS Simulator
Attachments:
'DrawPDFPage.zip' was successfully uploaded.
Relevant code:
UIGraphicsBeginImageContext(CGSizeMake(1024, 768));
CGContextRef context = UIGraphicsGetCurrentContext();
for (int i = 0; i < 100; ++i)
{
CGPDFDocumentRef document = CGPDFDocumentCreateWithURL((__bridge CFURLRef)url);
if (document)
{
CGPDFPageRef page = CGPDFDocumentGetPage(document, 1);
if (page)
{
CGContextDrawPDFPage(context, page);
}
CGPDFDocumentRelease(document);
}
[NSThread sleepForTimeInterval:1.0];
}
UIGraphicsEndImageContext();
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!