Unreproducible webcore crashes Unreproducible webcore crashes objective-c objective-c

Unreproducible webcore crashes


I had exactly the same issue in an app I worked on, it weirdly only occurred on older devices running iOS 7. I suspect this has something to do with them not being able to keep up.

What I had was a UITableView where one of the rows would open a UIViewController that had a UIWebView on it for custom adverts. What I found is that on the older devices objects and memory where being free'd up far more regularly than I'd seen in other platforms. I could mimic the crash very easily on an iPhone 4 by going in / out of the screen 2 or 3 times. Where as an iPhone 5 I spent 15 minutes doing the same and couldn't fault it.

I know you may feel like your controller is not being dealloc'd but it really sounds as though it is or some reference is being dropped, I have also seen my delegate references disappear a few times in this app also.

My advice and what worked for me is to stop the execution of the webview and set everything to nil when you can.

In one instance on my app I chose to do it on the viewWillDisappear callback, because in my circumstance it was gone from the user and recreated later, so I blanked everything like so:

[webView stopLoading];self.webView.delegate = nil;self.webView = nil;


Look at your Javascript-to-Objective-C code and if you are executing/calling javascript code make sure that script does not invoke new calls to Objective-C.

This is proper usage:

Javascript >> Objective-CObjective-C >> Javascript

This is reason for crash:

Objective-C >> Javascript >> Objective-C (here is possible crash depending on some race conditions)

Solution is specific for your project code. But easiest would be to wrap all Javascript in setTimeout() to schedule execution in Javascript thread. Here is simple example, your Objective-C code needs to execute this script:

storeUserPhoneNumber("011 123 4567");

Crash will happen if storeUserPhoneNumber function calls back to Objective-C code (directly or indirectly) in its body. To fix this just wrap code in setTimeout like this:

setTimeout(function() {    storeUserPhoneNumber("011 123 4567");}, 0);

What this accomplishes is to parse Javascript code from string and place it in function that is scheduled to be executed later on next event-loop tick releasing control back to Objective-C after parsing JS code.

Remember you need this fix on all Objective-C >> Javascript calls ;)