Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.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
N iphone的可变内存问题_Iphone - Fatal编程技术网

N iphone的可变内存问题

N iphone的可变内存问题,iphone,Iphone,我使用的是a1=[[NSMutableArray alloc]init];现在发布a1的最佳方式是什么 现在我在dealloc发布 我在viewdidload中分配a1并在那里显示10幅图像阅读以下内容: 然后这个: 一个基本的例子是: // get the party started NSMutableArray *tmpArray = [[NSMutableArray alloc] init]; // as an example, just copy some user defaults i

我使用的是a1=[[NSMutableArray alloc]init];现在发布a1的最佳方式是什么

现在我在dealloc发布

我在viewdidload中分配a1并在那里显示10幅图像

阅读以下内容:

然后这个:


一个基本的例子是:

// get the party started
NSMutableArray *tmpArray = [[NSMutableArray alloc] init];
// as an example, just copy some user defaults into the mutable array
tmpArray = [[userDefaults objectForKey:@"UserDefaultsExample"] mutableCopy];

// do something here with tmpArray (i.e. if ([tmpArray count] == 0) //do something)

// once you are done with tmpArray, go ahead and release it
[tmpArray release];

对于您的情况,您希望在完成阵列后释放阵列,即在viewDidLoad结束时,只要您真正完成阵列,它可能是一个安全的赌注。如果这样做,就不需要在.h文件中创建NSMutableArray对象,合成它并在dealloc中发布。相反,您只需像我上面所做的那样创建一个临时版本,并在显示完其中的图像后将其发布。

非常感谢,即使我发布了我的reatincount=1[a1 release]; NSLog@what您没有%d,[a1重新计入]=1如何使其为0?是否有必要跟踪所有数组和字符串reatinCount=0以优化内存??使用诸如mutableCopy之类的方便方法将对象放入自动释放池,以便您的保留计数可能不会立即为零。你可能需要一些额外的阅读:嘿,像这样的关键用户DefaultsExample可以做任何事吗???它只是一个文本,不是吗???或者别的什么。。您是否正在使用UserDefaultsExample any wer,而不是tmpArray=[[userDefaults objectForKey:@UserDefaultsExample]mutableCopy];阅读概述部分的第3段,了解它接受的数据类型:…用户默认值通过属性列表工作,因此它必须采用该格式。