CGContextDrawPDFPage 泄漏 100%
我尝试使用 CoreGraphics 绘制 pdf,一切正常,但在仪器中存在 100% 泄漏:CGContextDrawPDFPage(ctx, page2); 我用 CGPDFDocumentRelease() 发布;每次我使用 CGPDFDocumentCreateWithURL(); 有什么解决方案可以发布:CGContextDrawPDFPage?
- (void)drawRect:(CGRect)rect
{
if (state == 0) {
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSaveGState(ctx);
[[UIColor whiteColor] set];
CGContextFillRect(ctx, CGRectMake(0, 0, rect.size.width, rect.size.height));
CGContextGetCTM(ctx);
CGContextScaleCTM(ctx, 1, -1);
CGContextTranslateCTM(ctx, 45, -rect.size.height);
CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL(((CFURLRef)url));
CGPDFPageRef page = CGPDFDocumentGetPage(pdf, currentPage);
CGRect mediaRect = CGPDFPageGetBoxRect(page, kCGPDFCropBox);
CGContextScaleCTM(ctx, (678) / mediaRect.size.width,
(rect.size.height ) / (mediaRect.size.height));
CGContextSetInterpolationQuality(ctx, kCGInterpolationHigh);
CGContextSetRenderingIntent(ctx, kCGRenderingIntentDefault);
CGContextDrawPDFPage(ctx, page);
CGPDFDocumentRelease(pdf);
CGContextRestoreGState(ctx);
}
else
{
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSaveGState(ctx);
[[UIColor whiteColor] set];
CGContextFillRect(ctx, CGRectMake(0, 0, rect.size.width, rect.size.height));
CGContextGetCTM(ctx);
CGContextScaleCTM(ctx, 1, -1);
CGContextTranslateCTM(ctx, 6, -rect.size.height);
CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL(((CFURLRef)url));
CGPDFPageRef page = CGPDFDocumentGetPage(pdf, currentPage);
CGRect mediaRect = CGPDFPageGetBoxRect(page, kCGPDFCropBox);
CGContextScaleCTM(ctx, (497) / mediaRect.size.width,
(rect.size.height ) / (mediaRect.size.height));
// draw it
CGContextSetInterpolationQuality(ctx, kCGInterpolationHigh);
CGContextSetRenderingIntent(ctx, kCGRenderingIntentDefault);
CGContextDrawPDFPage(ctx, page);
CGPDFDocumentRelease(pdf);
CGContextRestoreGState(ctx);
//
CGContextSaveGState(ctx);
CGContextGetCTM(ctx);
CGContextScaleCTM(ctx, 1, -1);
CGContextTranslateCTM(ctx, 506, -rect.size.height);
CGPDFDocumentRef pdf2 = CGPDFDocumentCreateWithURL(((CFURLRef)url));
CGPDFPageRef page2 = CGPDFDocumentGetPage(pdf2, (currentPage + 1));
CGContextScaleCTM(ctx, (497) / mediaRect.size.width,
(rect.size.height ) / (mediaRect.size.height));
CGContextSetInterpolationQuality(ctx, kCGInterpolationHigh);
CGContextSetRenderingIntent(ctx, kCGRenderingIntentDefault);
//Leak 100%
CGContextDrawPDFPage(ctx, page2);
CGPDFDocumentRelease(pdf2);
CGContextRestoreGState(ctx);
}
}
我不知道为什么。有什么想法吗? 这是我的应用程序的唯一泄漏:( 我不明白泄漏来自哪里:s
PS:state = 0 = 纵向 state = 1 = 横向,所以我横向绘制 2 页。
I try to Draw a pdf with CoreGraphics, everything work fine but in instrument there is a 100% leak on : CGContextDrawPDFPage(ctx, page2);
I release with CGPDFDocumentRelease(); everytime i use CGPDFDocumentCreateWithURL();
There is any solution to release : CGContextDrawPDFPage ?
- (void)drawRect:(CGRect)rect
{
if (state == 0) {
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSaveGState(ctx);
[[UIColor whiteColor] set];
CGContextFillRect(ctx, CGRectMake(0, 0, rect.size.width, rect.size.height));
CGContextGetCTM(ctx);
CGContextScaleCTM(ctx, 1, -1);
CGContextTranslateCTM(ctx, 45, -rect.size.height);
CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL(((CFURLRef)url));
CGPDFPageRef page = CGPDFDocumentGetPage(pdf, currentPage);
CGRect mediaRect = CGPDFPageGetBoxRect(page, kCGPDFCropBox);
CGContextScaleCTM(ctx, (678) / mediaRect.size.width,
(rect.size.height ) / (mediaRect.size.height));
CGContextSetInterpolationQuality(ctx, kCGInterpolationHigh);
CGContextSetRenderingIntent(ctx, kCGRenderingIntentDefault);
CGContextDrawPDFPage(ctx, page);
CGPDFDocumentRelease(pdf);
CGContextRestoreGState(ctx);
}
else
{
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSaveGState(ctx);
[[UIColor whiteColor] set];
CGContextFillRect(ctx, CGRectMake(0, 0, rect.size.width, rect.size.height));
CGContextGetCTM(ctx);
CGContextScaleCTM(ctx, 1, -1);
CGContextTranslateCTM(ctx, 6, -rect.size.height);
CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL(((CFURLRef)url));
CGPDFPageRef page = CGPDFDocumentGetPage(pdf, currentPage);
CGRect mediaRect = CGPDFPageGetBoxRect(page, kCGPDFCropBox);
CGContextScaleCTM(ctx, (497) / mediaRect.size.width,
(rect.size.height ) / (mediaRect.size.height));
// draw it
CGContextSetInterpolationQuality(ctx, kCGInterpolationHigh);
CGContextSetRenderingIntent(ctx, kCGRenderingIntentDefault);
CGContextDrawPDFPage(ctx, page);
CGPDFDocumentRelease(pdf);
CGContextRestoreGState(ctx);
//
CGContextSaveGState(ctx);
CGContextGetCTM(ctx);
CGContextScaleCTM(ctx, 1, -1);
CGContextTranslateCTM(ctx, 506, -rect.size.height);
CGPDFDocumentRef pdf2 = CGPDFDocumentCreateWithURL(((CFURLRef)url));
CGPDFPageRef page2 = CGPDFDocumentGetPage(pdf2, (currentPage + 1));
CGContextScaleCTM(ctx, (497) / mediaRect.size.width,
(rect.size.height ) / (mediaRect.size.height));
CGContextSetInterpolationQuality(ctx, kCGInterpolationHigh);
CGContextSetRenderingIntent(ctx, kCGRenderingIntentDefault);
//Leak 100%
CGContextDrawPDFPage(ctx, page2);
CGPDFDocumentRelease(pdf2);
CGContextRestoreGState(ctx);
}
}
And I don't know why. Any idea?
This is the only leak of my app :(
I don't see where the leak come from :s
PS : state = 0 = portrait orientation
state = 1 = landscape so I draw 2 pages in landscape orientation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来您没有释放从 CGPDFDocumentGetPage 获取的 CGPDFPageRef 实例。
在适当的位置添加 page 和 page2 的内容。
Looks like you're not releasing the CGPDFPageRef instances you're getting from CGPDFDocumentGetPage.
Add that for page and page2 at the appropriate locations.