ios - Core Graphics 栅格数据未从内存中释放

标签 ios objective-c memory-management core-graphics

所以我让我的应用程序拍摄屏幕截图并使用下面的代码将其保存到相册...

- (void) save {
        UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0 );
        [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
        UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        UIImageWriteToSavedPhotosAlbum(theImage,nil,NULL,NULL);
        NSData*theImageData=UIImageJPEGRepresentation(theImage, 1.0 );
        [theImageData writeToFile:@"image.jpeg" atomically:YES];
    }

如何释放由 Core Graphics 分配的保存屏幕截图光栅数据的内存?

我的项目使用 ARC 进行内存管理。在测试应用程序如何分配内存时,我注意到在截屏后内存没有被释放,导致应用程序随着时间的推移变得缓慢。 Instruments 中的“Allocation Summary”告诉我数据类别是“CG 栅格数据”,负责的调用者是“CGDataProviderCreatWithCopyOfData”。

CFRelease()中有没有解决办法; ?

我的第一个应用程序,所以我很菜鸟,我浏览了互联网,试图解决这个问题,但没有成功...

最佳答案

您可以尝试将方法的内容包装到 @autorelease block 中。

@autoreleasepool {
...
}

关于ios - Core Graphics 栅格数据未从内存中释放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19752016/

相关文章:

ios - 尝试更改 MKPointAnnotation 颜色但丢失标题

ios - 为什么我们需要将 sqlite DB 文件移动到文档文件夹?我们可以从 bundle 访问并对其执行数据库操作吗?

c++ - 有一个单独的 "operator new[]"的目的是什么?

ios - 如何检测用户何时尝试刷卡 "past UIScrollView content offset"?

ios - Apple 的 ResearchKit 中的额外本地化是否导致 iOS App Store 错误地认为我们的应用程序已针对许多其他语言进行了本地化?

ios - CollectionView prepareForSegue 不将图像数据发送到 DetailView

ios - 如何避免 UICollectionView 重复单元格?

c - 如何使指向全局结构数组的指针

c++ - !heap -s 命令的输出需要说明

iOS5:模式 UIViewController 播放 Youtube 视频时 UIWebView 出现异常