开发者

Problem when remove allobjects used with nsmutablearray

    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);
开发者_StackOverflow

My code is as above i do get two objects in log but both are empty i dont know wheather to use remove all objects or to dealloc for ary_Temp .Should i use removeAllobjects or alloc it everytime after i add it to aryDescListing.

Thanks


Don't use dealloc, instead use release. dealloc will deallocate the object without taking in count the retain count of it and it will break your app sooner or later.

Perhaps you want this? :

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 will remove the objects from the array (and will decrease their retainCount by one) but not will release the array.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜