0

My beta users are seeing the following crash on average once an hour:

0   libobjc.A.dylib                 0x33182f78 objc_msgSend + 16
1   Foundation                      0x3497e4f8 __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_0 + 12
2   CoreFoundation                  0x35530540 ___CFXNotificationPost_block_invoke_0 + 64
3   CoreFoundation                  0x354bc090 _CFXNotificationPost + 1400
4   Foundation                      0x348f23e4 -[NSNotificationCenter postNotificationName:object:userInfo:] + 60
5   Foundation                      0x348f3c14 -[NSNotificationCenter postNotificationName:object:] + 24
6   libdispatch.dylib               0x338f1c52 _dispatch_call_block_and_release + 6
7   libdispatch.dylib               0x338fce8a _dispatch_main_queue_callback_4CF$VARIANT$up + 190
8   CoreFoundation                  0x355372a6 __CFRunLoopRun + 1262
9   CoreFoundation                  0x354ba49e CFRunLoopRunSpecific + 294
10  CoreFoundation                  0x354ba366 CFRunLoopRunInMode + 98
11  GraphicsServices                0x33255432 GSEventRunModal + 130
12  UIKit                           0x32c92cce UIApplicationMain + 1074
13  Ars Logica                      0x00039ecc main (main.m:16)
14  Ars Logica                      0x00039e80 start + 32

I have two complications:

1) I don't make any calls to NSNotificationCenter.

2) Despite extensive efforts I've never gotten this to happen while running with XCode.

There is no correlation I can find between low memory reports and the crash events.

Frankly I'm not sure where to go from here. Complication number 2 is obviously a big problem.

Any suggestions or pointers would be much appreciated.


As a matter of record this turned out to be a crash in the iAd framework. Specifically I was keeping a full page interstitial ad ready to go as per the Apple examples but I wasn't invalidating it when I was put into the background. When I came out of the background sometimes a notification saying that attachment to the ad server had been lost was sent to the old context. Invalidating the ad context when going to the background fixed everything up nicely.

Tim Kolar
  • 175
  • 1
  • 9

1 Answers1

4

Your best bet is probably to use method swizzling and a category to replace:

+ addObserver:selector:name:object:

in NSNotificationCenter.

with your own version that logs the contents of all arguments, then calls the real version. That way when your testers see a crash they can look at device logs to see what the last thing passed into that method was doing. That may give you enough insight to figure out what area of the system is using notification center.

Also, are you using ARC? Using ARC I would be very surprised if an error like this could occur, it seems like you are passing something into the system which then gets attached to a notification somehow behind the scenes, but is deallocated while the system still has a reference.

Here's one example of method swizzling pertinent to your need (replacing a class level method):

How to swizzle a class method on iOS?

Obviously don't ship to the store with that in place...

Community
  • 1
  • 1
Kendall Helmstetter Gelner
  • 74,769
  • 26
  • 128
  • 150
  • I was afraid of that, more logging is your best hope then I fear. Also while in XCode have you tried repeatedly triggering memory warnings in the simulator when in different parts of the code? – Kendall Helmstetter Gelner Mar 26 '13 at 05:52
  • Yes, I've been pretty comprehensive with the memory warnings. I think swizzling is the way to go. – Tim Kolar Mar 28 '13 at 23:47