• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSMutableArray + NSEnumerator = No Memory
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: NSMutableArray + NSEnumerator = No Memory
      • From: Alastair Houghton <email@hidden>
References: 
 >Re: NSMutableArray + NSEnumerator = No Memory (From: Chris Suter <email@hidden>)

  • Prev by Date: Re: NSMutableArray + NSEnumerator = No Memory
  • Next by Date: insert a plist in a NSTableView using a NSDictionary
  • Previous by thread: Re: NSMutableArray + NSEnumerator = No Memory
  • Next by thread: Re: NSMutableArray + NSEnumerator = No Memory
  • Index(es):
    • Date
    • Thread