Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone I';m使用图形图像上下文为UIView动画数组预处理图片。如果不再需要此阵列,如何释放内存?_Iphone_Xcode_Memory Management_Uiviewanimation - Fatal编程技术网

Iphone I';m使用图形图像上下文为UIView动画数组预处理图片。如果不再需要此阵列,如何释放内存?

Iphone I';m使用图形图像上下文为UIView动画数组预处理图片。如果不再需要此阵列,如何释放内存?,iphone,xcode,memory-management,uiviewanimation,Iphone,Xcode,Memory Management,Uiviewanimation,我正在使用图形图像上下文为UIView动画数组预处理图片 如果我不再需要此阵列和所有这些图像,如何释放内存?\u picturearlay=nil足够吗 - (NSMutableArray *)generateCachedImageArrayWithFilename:(NSString *)filename extension:(NSString *)extension andImageCount:(int)count { _imagesArray = [[NSMutableArray

我正在使用图形图像上下文为
UIView
动画数组预处理图片

如果我不再需要此阵列和所有这些图像,如何释放内存?
\u picturearlay=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;
}
-(NSMutableArray*)generateCachedImageArrayWithFilename:(NSString*)文件扩展名:(NSString*)扩展名和图像计数:(int)计数
{
_imagesArray=[[NSMutableArray alloc]init];
_fileExtension=扩展;
_imageName=文件名;
_imageCount=计数;
for(int i=0;i
只需从阵列中删除要释放的图像即可 或者在数组上调用
removeAllObjects
,将其清除

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


  • 可以使用
    removeObject
    removeAllObjects

  • 释放阵列可以通过以下方式完成:

    • (非arc)调用
      release
    • (使用arc)将其设置为nil(但这不可靠),因此我将其称为'removeAllObjects'

只需从阵列中删除要释放的图像即可 或者在数组上调用
removeAllObjects
,将其清除

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


  • 可以使用
    removeObject
    removeAllObjects

  • 释放阵列可以通过以下方式完成:

    • (非arc)调用
      release
    • (使用arc)将其设置为nil(但这不可靠),因此我将其称为'removeAllObjects'

将数组分配给nil不会释放分配给数组的内存,您需要释放分配给数组的内存。您可以返回[\u imagesArray autorelease];并保留使用此阵列的任何位置。一旦你使用完数组,你就可以释放它。@NuzhatZari我在ARC下,所以自动释放对我不起作用。将数组赋值为nil不会释放分配给数组的内存,你需要释放分配给数组的内存。你可以返回[_ImageSarrayAutorelease];并保留使用此阵列的任何位置。一旦你们使用完数组,你们就可以释放它。@NuzhatZari我在ARC下,所以自动释放对我不起作用。