Re: NSMutableArray + NSEnumerator = No Memory
Re: NSMutableArray + NSEnumerator = No Memory
- Subject: Re: NSMutableArray + NSEnumerator = No Memory
- From: James Bucanek <email@hidden>
- Date: Sun, 23 Sep 2007 11:39:51 -0700
Chris Suter <mailto:email@hidden> wrote (Sunday,
September 23, 2007 4:18 PM +1000):
On 23/09/2007, at 4:36 AM, James Bucanek wrote:
1 - Use objectAtIndex: to iterate through the array.
2 - Create an auto release pool and discard the NSEnumerator
during every search.
3 - Abandon NSArray and roll my own collection.
I'm leaning towards (1) because it minimizes the code change
and shouldn't incur too much additional overhead. (2) will
keep me from running out of memory, but doesn't guarantee that
other calls to objectEnumerator won't make gratuitous copies
of the array.
(3) is ultimately the best solution, as I can increase the
speed and reduce the memory footprint of the collection
considerably by dropping NSArray altogether. But that's a lot
of coding and I'd rather not make any radical changes in my
application at the moment.
There is a fourth option which is that you implement your own enumerator. Something like this would do:
<code snipped>
That's an excellent solution, Chris. It has the advantage that
it's a drop-in replacement for NSEnumerator in my code. It has
the disadvantage that it's just a layer of abstraction over
objectAtIndex:, so it would be slower than the built-in
NSEnumerator. But it's worth profiling to see just home much slower.
James
--
James Bucanek
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden