1

我正在UIView使用图形图像上下文为动画数组预缓存图片。

如果我不再需要这个数组和所有这些图像,我该如何释放内存?够_pictureArray = nil了吗?

- (NSMutableArray *)generateCachedImageArrayWithFilename:(NSString *)filename extension:(NSString *)extension andImageCount:(int)count
{
    _imagesArray = [[NSMutableArray alloc] init];
    _fileExtension = extension;
    _imageName = filename;
    _imageCount = count;

    for (int i = 0; i < count; i++)
    {
        NSString *tempImageNames = [NSString stringWithFormat:@"%@%i", filename, i];
        NSString *imagePath = [[NSBundle mainBundle] pathForResource:tempImageNames ofType:extension];

        UIImage *frameImage = [UIImage imageWithContentsOfFile:imagePath];
        UIGraphicsBeginImageContext(frameImage.size);
        CGRect rect = CGRectMake(0, 0, frameImage.size.width, frameImage.size.height);
        [frameImage drawInRect:rect];
        UIImage *renderedImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();

        [_imagesArray addObject:renderedImage];

        if (_isDoublingFrames)
        {
            [_imagesArray addObject:renderedImage];
        }
        else if (_isTripplingFrames)
        {
            [_imagesArray addObject:renderedImage];
            [_imagesArray addObject:renderedImage];
        }

        NSLog(@"filename = %@", filename);
    }

    return _imagesArray;
}
4

1 回答 1

1

只需从数组中删除要释放的图像或调用removeAllObjects数组来清除它

因为数组是唯一保存图像的数组(假设您现在不显示它)


  • 从数组中释放项目可以使用removeObjectremoveAllObjects

  • 可以通过以下方式释放数组:

    • (非弧)呼叫release
    • (带弧)将其设置为零(但这不可靠。)所以我会调用“removeAllObjects”
于 2013-04-26T07:30:55.047 回答