删除与nsmutablearray一起使用的allobject时出现问题

时间:2011-06-10 06:20:50

标签: xcode nsarray

    aryDesc = [[NSMutableArray alloc]init]; 
    NSMutableArray *ary_Temp ;
ary_Temp = [[NSMutableArray alloc]init ];
[ary_Temp addObject:@"Collins Burns"];
[ary_Temp addObject:@"cburns"];
[ary_Temp addObject:@"Active"];


    [aryDescListing addObject:ary_Temp];
[ary_Temp removeAllObjects];


[ary_Temp addObject:@"Collins Burns"];
[ary_Temp addObject:@"cburns"];
[ary_Temp addObject:@"Active"];


[aryDescListing addObject:ary_Temp];
    [ary_Temp removeAllObjects];

    NSLog(@"ary Description===== >>>%@",aryDescListing);

我的代码如上所述我在日志中获得了两个对象,但两者都是空的我不知道要使用删除所有对象还是deryoc for ary_Temp。我应该使用removeAllobjects,或者每次将它添加到aryDescListing后分配它。 / p>

谢谢

1 个答案:

答案 0 :(得分:1)

请勿使用dealloc,而是使用releasedealloc将取消分配对象而不计算其保留计数,它会迟早破坏您的应用。

也许你想要这个? :

aryDesc = [[NSMutableArray alloc] init]; 
NSMutableArray *ary_Temp ;

ary_Temp = [[NSMutableArray alloc] init];
[ary_Temp addObject:@"Collins Burns"];
[ary_Temp addObject:@"cburns"];
[ary_Temp addObject:@"Active"];
[aryDescListing addObject:ary_Temp];
[ary_Temp release];

ary_Temp = [[NSMutableArray alloc] init];
[ary_Temp addObject:@"Collins Burns"];
[ary_Temp addObject:@"cburns"];
[ary_Temp addObject:@"Active"];
[aryDescListing addObject:ary_Temp];
[ary_Temp release];

NSLog(@"ary Description===== >>>%@",aryDescListing);

BTW:removeAllObject将从数组中删除对象(并将其retainCount减少一个)但不会释放数组。