• 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: Saving NSDictionary, Enumeration error
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Saving NSDictionary, Enumeration error


  • Subject: Re: Saving NSDictionary, Enumeration error
  • From: Jens Alfke <email@hidden>
  • Date: Tue, 07 May 2013 11:06:50 -0700

On May 7, 2013, at 7:04 AM, Tamas Nagy <email@hidden> wrote:

> The data collecting and save happening on the main thread, but the objects providing the data may run on an other - rendering - thread. Maybe its a problem with an object while collecting the save data, and I forgot about copy the value?

Copying the value isn't enough! Foundation collections are not thread-safe — you shouldn't access a dictionary (or array or set or string) on one thread while modifying it on another. The only safe way to share these objects is read-only. (There's a whole document in Apple's doc-set about the thread-safety of various Cocoa classes. In general, never assume a class is thread-safe unless the docs explicitly say so.)

In this specific crash, the presence of "__NSFastEnumerationMutationHandler" in the exception backtrace shows that the enumerator detected that the dictionary had been modified during the enumeration, which is illegal (even on a single thread.)

—Jens
_______________________________________________

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: Saving NSDictionary, Enumeration error
      • From: Tamas Nagy <email@hidden>
References: 
 >Saving NSDictionary, Enumeration error (From: Tamas Nagy <email@hidden>)
 >Re: Saving NSDictionary, Enumeration error (From: Igor Elland <email@hidden>)
 >Re: Saving NSDictionary, Enumeration error (From: Tamas Nagy <email@hidden>)

  • Prev by Date: Re: Wanted: new owner for Mac apps
  • Next by Date: Re: Cocoa-dev Digest, Vol 10, Issue 276
  • Previous by thread: Re: Saving NSDictionary, Enumeration error
  • Next by thread: Re: Saving NSDictionary, Enumeration error
  • Index(es):
    • Date
    • Thread