views:

1443

answers:

4

I'm experiencing crashes of an app that uses UIWebView. Usually it's when page is not fully loaded and UIWebView is sent stopLoading selector. Or when UIWebView fully loaded page. I've got EXC_BAD_ACCESS. Stack looks like this:

#0  0x95bb7688 in objc_msgSend
#1  0x30a671db in -[UIWebView webView:decidePolicyForNavigationAction:request:frame:decisionListener:]
#2  0x3024a10d in __invoking___
#3  0x30249ff8 in -[NSInvocation invoke]
#4  0x358ab160 in HandleDelegateSource
#5  0x302452c1 in CFRunLoopRunSpecific
#6  0x30244628 in CFRunLoopRunInMode
#7  0x32044c31 in GSEventRunModal
#8  0x32044cf6 in GSEventRun
#9  0x309021ee in UIApplicationMain
#10 0x0000239c in main at main.m:13

for me most strange thing here is webView:decidePolicyForNavigationAction:request:frame:decisionListener: selector sent to UIWebView, because there is no such selector in UIWebView documentation! Only for Cocoa (not cocoa touch) WebView. I suspect that there is something wrong with UIWebView or its delegate. But I can't set breakpoint to watch them. Please advise how I can get more info in this situation.

A: 

Try turning on NSZombie and see if something is being released too soon.

It may be that you are canceling the loading of the view and then immediately tearing down your view hierarchy, causing something to be released before the UIWebView is done messing with it.

In this case, the backtrace looks distinctly like it is a delegate that is being released early. Delegate relationships are typically weak and, lacking GC, are a wonderful source for dangling references that causes crashes that look just like this.

bbum
+5  A: 

You have to stop loading the webView and delete the delegate before leaving the view:

- (void)dealloc {
    webView.delegate = nil;
    [webView stopLoading];
    [webView release];
    [super dealloc];
}

Cheers,

Ondrej


iPhone SDK tutorials

Ondrej
Thanks. This solve my EXC_BAD_ACCESS problem.
Gaius Parx
happy to help :)
Ondrej
A: 

It's a little annoying that I can't comment on this. Just to say.. hey Ondrej your solution helped me fix my problem. Thanks.

FredArters
A: 

Hi andreej still facing crash,

@synchronized(self) { [webView_ stopLoading]; [webView_ removeFromSuperview]; [webView_ setDelegate:nil]; [webView_ release]; webView_ = nil; [self removeFromSuperview]; } The original code above:

em getting this error, By enabling NSZombie i get these two kind of messages at different time

1.

  -[UIWebView webView:decidePolicyForNavigationAction:request:frame:decisionListener:]: message sent to deallocated instance 0x2eeff0

2.

  -[UIScroller window]: message sent to deallocated instance 0xaf3bf10

Most of the time i get message 1.

Now if i not release the uiwebview then unable to produce the crash.

Wht i think for solution to release the uiwebview after some 100ms delay, so to avoid these.

Any recommendations / suggestions

Sajjeel