0

I am getting a EXC_BAD_ACCESS (code=2, address=0x8) error when trying to post a notification.

Occasionally I will see:

-[__NSMallocBlock__ handleMessagesReceived:]: unrecognized selector sent to instance 0x9855cd0

The notification post code looks like this:

NSDictionary *notificationInfo = [NSDictionary dictionaryWithObject:outputArray forKey:@"messages"];
[[NSNotificationCenter defaultCenter] postNotificationName:kMESocialHeatmapMessagesReceivedNotification object:nil userInfo:notificationInfo];

The observer code looks like this (this is the only handler for that notification):

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleMessagesReceived:) name:kMESocialHeatmapMessagesReceivedNotification object:nil];

And the handler code:

- (void)handleMessagesReceived:(NSNotification *)notification {...}

I have cleaned the project (CMD-SHIF-K, CMD-ALT-SHIFT-K and removed derived data from the Organizer), restarted both Xcode and my machine, and even re-written the involved code. Same issue, and I just don't see that problem.

Any insight GREATLY appreciated.

Cheers,

Chris

========== UPDATE (cannot answer my own question...) ============

Cheers, Phillip and rang, that pointed me in the right direction.

I do understand that EXC_BAD_ACCESS indicates a dealloc'd object, but in this case that just wasn't possible since the main class of the system was holding onto the object in question (the Heatmap).

The problem turned out to be a race condition between the creation of the Heatmap and the populating of the data model it shares. The populating was happening, occasionally, before the Heatmap was finished being created (both are event-driven).

I ended up re-working the code so that the class holding the Heatmap makes a synchronous call to populate the data after the Heatmap is cleaner.

Thanks for the input, it saved me a headache. :)

Chris

Raconteur
  • 1,381
  • 1
  • 15
  • 29
  • After you add `self` as an observer, it seems that `self` object is being deallocated. What kind of object is handling the notification and how is it created and retained? – Phillip Mills May 23 '12 at 18:39
  • Cheers, Phillip. That pointed me in the right direction. I understand that EXC_BAD_ACCESS indicates a dealloc'd object, but in this case that just wasn't possible. – Raconteur May 23 '12 at 20:01

2 Answers2

0

Error EXC_BAD_ACCESS is an error comes by releasing an object without initializing or sending message to released object, check this question for more information on EXC_BAD_ACCESS

Community
  • 1
  • 1
Ranganadh Paramkusam
  • 4,258
  • 2
  • 22
  • 33
0

The problem turned out to be a race condition between the creation of the Heatmap and the populating of the data model it shares. The populating was happening, occasionally, before the Heatmap was finished being created (both are event-driven).

I ended up re-working the code so that the class holding the Heatmap makes a synchronous call to populate the data after the Heatmap is cleaner.

Thanks for the input, it saved me a headache. :)

Chris

Raconteur
  • 1,381
  • 1
  • 15
  • 29