Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
核心图形iOS内存增加/泄漏_Ios_Objective C_Pdf_Memory Leaks_Core Graphics - Fatal编程技术网

核心图形iOS内存增加/泄漏

核心图形iOS内存增加/泄漏,ios,objective-c,pdf,memory-leaks,core-graphics,Ios,Objective C,Pdf,Memory Leaks,Core Graphics,我有一个带有自定义UIView的UIViewController。此自定义UIView使用drawRect和CoreGraphics绘制pdf。UIViewController(pdfViewController)被多次加载: [self.revealViewController setFrontViewController:[[pdfViewController alloc]initWithPDF:pdfs[indexPath.row]uiColor:[self-colorWithRGB:co

我有一个带有自定义UIView的UIViewController。此自定义UIView使用
drawRect
和CoreGraphics绘制pdf。UIViewController(pdfViewController)被多次加载:

[self.revealViewController setFrontViewController:[[pdfViewController alloc]initWithPDF:pdfs[indexPath.row]uiColor:[self-colorWithRGB:colors[indexPath.row][0]];
自定义UIView如下所示:

-(void)drawRect:(CGRect)rect
{
[超级drawRect:rect];
NSString*documentsDirectory=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES)[0];
NSURL*url=[NSURL fileURLWithPath:[DocumentsDirectoryStringByAppendingPathComponent:PDF]];
//获取图形上下文
CGContextRef ctx=UIGraphicsGetCurrentContext();
//打开PDF文档
CGPDFDocumentRef pdfDocument=CGPDFDocumentCreateWithURL((CFURLRef)url);
CGPDFPageRef pdfPage=CGPDFDocumentGetPage(pdfDocument,第页);
//获取PDF维度
CGRect cropRect=cgpfpagegetboxrect(pdfPage,kCGPDFCropBox);
//设置白色背景
CGContextSetRGBFillColor(ctx,255.0,255.0,255.0,1.0);
CGContextFillRect(ctx,rect);
//翻转坐标并重置原点
CGContextGetCTM(ctx);
CGContextScaleCTM(ctx,1,-1);
CGContextTranslateCTM(ctx,0,-rect.size.height);
//设置渲染质量
CGContextSetInterpolationQuality(ctx、kCGInterpolationHigh);
//尺度矩阵
CGContextScaleCTM(ctx,rect.size.height/cropRect.size.height,rect.size.height/cropRect.size.height);
CGContextTranslateCTM(ctx,-cropRect.origin.x,-cropRect.origin.y);
//绘制PDF
CGContextDrawPDFPage(ctx,pdfPage);
CGPDFPageRelease(pdfPage);
CGPDFDocumentRelease(pdfDocument);
}
内存不会被释放,并且每次使用UIViewController加载UIView时,内存都会增加约6MB:/

以下是内存使用情况的图像:

任何帮助都将不胜感激,请随时询问更多信息

更新:
drawRect
中的UIViews手动内存管理非常好。由于(强)委托引用,UIView本身没有释放自身。再次感谢所有的回答

听起来UIView本身并没有发布。(既然我们在评论中找到了答案,不妨现在就填写一下。)

嗯,是吗?您注释掉了发布资源:
//CGContextRelease(ctx)。这背后的想法是什么?取消这一行的注释会引发警告,应用程序会崩溃:CGContextResetState:invalid context 0x10953d010。这是一个严重的错误。此应用程序或其使用的库正在使用无效的上下文,从而导致系统稳定性和可靠性的整体降级。此通知是出于礼貌:请解决此问题。这将成为即将进行的更新中的致命错误。调用CGContextRelease()的问题在于您没有创建它。这只是系统希望您绘制的已经存在的上下文。那么,如何完全卸载内存以避免内存泄漏?这是在ARC还是手动内存管理下?