-2

My application includes a singleton class represents general data. The latter contains the following atomic property :

// .h file
@property (atomic, strong) NSMutableDictionary *dataDictionary;

// .m file
@synthesize dataDictionary;

The dictionary is being used simultaneously from different threads (both setter and getter), and worked as normal without any crashes on iOS 6.0 - 8.4. Recently I have run the application on iOS 9.0 simulator and it crashed (EXC_BAD_ACCESS) in arbitrary code calling the dictionary setObject:forKey: method.

  1. Does anyone knows what have changed in iOS 9.0 that can cause those crashes ?
  2. Any clue how to solve this issue ?

enter image description here

enter image description here

Tsahi Deri
  • 571
  • 1
  • 3
  • 14

2 Answers2

2

atomic on a property doesn't mean what you think it does. atomic means that the property value itself (i.e. the pointer) is protected from parallel access, but it doesn't protect the contents of the dictionary at all.

If your code worked on previous versions of iOS, then it was completely by fluke. Your code will crash randomly if you are allowing multiple threads to access a single NSMutableDictionary in this way.

You need to add a locking discipline of some sort between these multiple threads.

Ewan Mellor
  • 6,747
  • 1
  • 24
  • 39
0

I think you should use nonatomic instead of atomic

Dipen
  • 268
  • 1
  • 14