After some relatively safe (as for me) modifications the app began crashing on some WebKitLegacy stuff. I see many crashes in Fabric but can't find stable steps to reproduce. Does anyone know what can cause those crashes? Please see images attached.
Some app screens use UIWebView to display content - I assume that the problem is somewhere there.
UIWebView EXC_BAD_Address ...Application received signal First of All, you should think about the webView.delegate = nil. But where ??
My experience:
- (void)dealloc{
/*
Important
Before releasing an instance of UIWebView for which you have set a delegate,
you must first set the UIWebView delegate property to nil before disposing of the UIWebView instance.
This can be done, for example, in the dealloc method where you dispose of the UIWebView.
*/
if (_webView.loading) {
[self.webView stopLoading];
}
_webView.delegate = nil;
}
if the
ViewController
is a child of a anotherViewController
, you can trigger the removal of theViewController
's view from the parentViewController
's view with an animation. At the same time, you can remove theViewController
from its parent and nil out its reference. at this pointViewController
will be nil andviewWillDisappear
will never be called, meaning **the WebView delegate will never be cleaned up ** Use dealloc and ensure that yourWebView
is always cleaned up.
Other excellent linking ios:EXC_BAD_ACCESS for Webview delegate
As far as I remember, that signal popped up when a Webview received an update (for example, a response from an embedded image), but it couldn't be rendered because it's not used by the main thread anymore. That means, when the ViewController is not being displayed.
If that's the case, you should be able to reproduce the issue by loading a web page with heavy content (for example, some online newspaper like http://edition.cnn.com/) and dismissing the webview immediately after starting the load, by pushing/popping another ViewController.
How to fix it: indeed, you need to call the methods you mentioned:
webview.delegate = nil;
[webview stopLoading];
However, the place to do so is on the viewWillDisappear
method, never on dealloc
. The reason is simple: viewWillDisappear
is called on the exact moment where the ViewController is about to lose control of the main thread. However, dealloc
is called when the VC is about to be released to the heap. This might happen some seconds after, giving the app some precious time to crash, or maybe will never be called at all. Moving both methods there should do the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With