7

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

- (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 中的“分配摘要”告诉我数据类别是“CG 栅格数据”,负责的调用者是“CGDataProviderCreatWithCopyOfData”。

CFRelease() 中是否有解决方案;?

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

4

1 回答 1

0

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

@autoreleasepool {
...
}
于 2013-11-03T11:20:29.350 回答