In my ChatMessage class I have the weak reference to Chat class
@interface ChatMessage : NSObject
@property (nonatomic, weak) Chat *chat;
I make the following initialization within Chat implementation on the global queue
ChatMessage *chatMessage = [[ChatMessage alloc] initWithDictionary:dictionary];
chatMessage.chat = self;
and get very strange error at the second line
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x4c008be5
Triggered by Thread: 17
Thread 17 Crashed:
0 libobjc.A.dylib 0x39f535d2 cache_getImp + 18
1 libobjc.A.dylib 0x39f4e9a8 lookUpImpOrForward + 28
2 libobjc.A.dylib 0x39f4e942 lookUpImpOrNil + 22
3 libobjc.A.dylib 0x39f48aca class_getMethodImplementation + 30
4 libobjc.A.dylib 0x39f5833a weak_register_no_lock + 38
5 libobjc.A.dylib 0x39f586fa objc_storeWeak + 106
6 MyMessenger 0x000d366c -[ChatMessage setChat:]
7 MyMessenger 0x001173bc -[Chat getMessagesForPage:]
8 libdispatch.dylib 0x3a432d50 _dispatch_call_block_and_release + 8
9 libdispatch.dylib 0x3a438684 _dispatch_root_queue_drain + 224
10 libdispatch.dylib 0x3a4388d8 _dispatch_worker_thread2 + 52
11 libsystem_pthread.dylib 0x3a563c14 _pthread_wqthread + 296
12 libsystem_pthread.dylib 0x3a563ad8 start_wqthread + 4
Did someone come across such problems with setting weak properties?
It appears that the problem is in simultaneous access to this weak property from different threads.
Weakness of the property doesn't allow us to neglect multithread assigning.
The safe rule to work with datasources is to change it synchronously within one selected thread.