【发布时间】:2013-12-25 16:43:55
【问题描述】:
我希望枚举我的相册,但是当我在我的设备上测试应用程序时,应用程序在 30 秒后崩溃。当我使用 Instrument 时,我发现 ARC 不会自动释放资产,因此每次处理图像时,它都会分配图像大小。我的主要目标是只显示设备的屏幕截图。所以假设我有 1000 张照片,在 30 张图片之后我得到 30MB 分配,这会导致崩溃。如何显式释放内存?
这是我的代码:
[self.assetsGroup enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
if (result) {
ALAssetRepresentation* representation = [result defaultRepresentation];
// Retrieve the image orientation from the ALAsset
UIImageOrientation orientation = UIImageOrientationUp;
NSNumber* orientationValue = [result valueForProperty:@"ALAssetPropertyOrientation"];
if (orientationValue != nil) {
orientation = [orientationValue intValue];
}
CGFloat scale = 1;
UIImage* image = [UIImage imageWithCGImage:[representation fullResolutionImage]
scale:scale orientation:orientation];
if ( image.size.height/2==screenHeight && image.size.width/2==screenWidth)
[self.assets addObject:result];
}
}];
我认为默认表示会导致 malloc。
提前谢谢...
【问题讨论】:
-
在将 ALAsset 添加到资产数组后立即尝试“
image = nil;”会发生什么? -
试过了,但没有用。可能是由于强类型问题。
标签: memory automatic-ref-counting enumeration alassetslibrary