所以我让我的应用程序拍摄屏幕截图并使用下面的代码将其保存到相册...
- (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/