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

use*_*513 7 memory-management core-graphics objective-c ios

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

- (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];
    }
Run Code Online (Sandbox Code Playgroud)

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

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

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

我的第一个应用程序,所以我很漂亮,我已经浏览了互联网,尝试解决问题,没有运气...

Mun*_*ndi 0

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

@autoreleasepool {
...
}
Run Code Online (Sandbox Code Playgroud)