• 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: "Philip Q" <email@hidden>
  • Date: Mon, 24 Sep 2007 19:10:13 +1200

On 23/09/2007, James Bucanek <email@hidden> wrote:
> I was eventually able to isolate the problem; My application is
> running out of memory. The crash occurs at
>
>      NSMutableArray* files;
>      ...
>      NSEnumerator* e = [files objectEnumerator];  <-- crashes in
> CFArrayGetValues > __memcpy
>

I think the problem is that you are using an NSMutableArray:
The contents of a mutable array can be modified at any time, this is
problematic for an enumerator as if the array is modified while it is
enumerating through it, it could end up skipping elements or some
other funky behaviour (even thought the documentation discourages this
type of modification).

The behaviour you're seeing is a way to combat that---make a copy of
all the references in the array at the time of creation of the
enumerator and enumerate though that list (which will never change).

If you make a single copy of the array with [NSArray
arrayWithArray:files] (which is what Chris' MemoryEfficientEnumerator
wraps), and use that for your enumerator, you should get more
memory-efficient, an safe behaviour (DISCLAIMER: I haven't actually
tested this, it just seems sensible).

-Phil
_______________________________________________

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: James Bucanek <email@hidden>
References: 
 >NSMutableArray + NSEnumerator = No Memory (From: James Bucanek <email@hidden>)

  • Prev by Date: Re: Sort a NSArrayController using case-insensitive compare, possible ?
  • Next by Date: Issue with RootDirectory key in launchd plist file
  • Previous by thread: Re: NSMutableArray + NSEnumerator = No Memory
  • Next by thread: Re: NSMutableArray + NSEnumerator = No Memory
  • Index(es):
    • Date
    • Thread