On a related, yet different note... I run into this all the time where I need to iterate through an NSMutableArray (or set, etc, etc) and remove some of the items. My normal pattern has been this:
NSMutableSet *removeSet = [[NSMutableSet alloc] init]; for(NSObject *foo in myArray) { if(needToRemoveFoo) { [removeSet addObject:foo]; } } for(NSObject *foo in removeSet) { [myArray removeObject:foo]; } [removeSet release]; If I have to do multiple passes at the objects in myArray, I'll sometimes do [removeSet removeAllObjects] instead of [removeSet release] and reuse the NSMutableSet object as necessary. Would it be better in general to make a copy of myArray in this case and remove the objects directly from myArray as I iterate over the copy? Or are the two methods generally equal in terms of performance and memory usage? I am currently doing this on the iPhone, so I am concerned with my memory and CPU usage more than I would be on the Mac. I also happen to be doing this once every 30th or 60th of a second as part of my update loop in a game. Thanks! On Mon, Nov 30, 2009 at 2:36 PM, Nick Zitzmann <n...@chronosnet.com> wrote: > What happens if you try enumerating on a copy of the sublayer array? That's > what I usually do in this situation... > -- dennis _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com