0
    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);

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

5
  • removeAllObjects does not release the array itself, whether NSLog(@"%@",ary_Temp) working correctly before and after the removeAllobject.. Commented Jun 10, 2011 at 6:29
  • I have executed your code.But I am getting the output like this ary Description===== >>>( ( "Collins Burns", cburns, Active ), ( "Collins Burns", cburns, Active ) ) Commented Jun 10, 2011 at 6:31
  • remove allobjects means it removes only objects,this is not releasing the objects.If you want to release the objects means use the release whereever you want. Commented Jun 10, 2011 at 6:33
  • @arnold I am getting two object in aryDescListing and both are empty. Commented Jun 10, 2011 at 6:33
  • please create a new project and paste your code whatever you have asked. Commented Jun 10, 2011 at 6:35

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

is allocating and releasing array multiple times say for atleast hunderads of time is really good from programming point of view .Thanks for your inputs, is there other way to do this ..
what exactly you want to do? have an array with 6 objects? an array of arrays? an array of two arrays only? That answer was a guess since I what you wan't is not really clear in my opinion.
@mugen your question sounds like premature optimization. Unless you have a specific, quantified, performance problem, then you shouldn't be concerned.
@mugen From a programming point of view the most clear and understandable code is best. Then profile to find the real hot spots that need optimization.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.