Dan Hanly
Dan Hanly

Reputation: 7839

EXC_BAD_ACCESS when removing a view

I have a problem with EXC_BAD_ACCESS.

I have a UIWebView that loads a local HTML file and as the app is loading the contents of the view I display a UIView on top of it as a "splash screen". Then when the contents of the UIWebView are loaded I run an animation to fade-out the UIView and remove it from memory.

- (void) webViewDidFinishLoad:(UIWebView *)webView {
        [UIView animateWithDuration:1
                 animations:^{
                      loadingView.alpha = 0.0;
                 }
                 completion:^(BOOL finished){
                     [loadingView removeFromSuperview];
                     [loadingView release];
                 }];
}

The issue is, that when I use the my app fails on the two lines within the completion method. The full error:

Program received signal:  “EXC_BAD_ACCESS”.
warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3 (8F190)/Symbols/Developer/usr/lib/libXcodeDebuggerSupport.dylib (file not found).

The loadingView is built through interface builder. Here's the heirarchy:

Image

Upvotes: 0

Views: 716

Answers (2)

Stephen Darlington
Stephen Darlington

Reputation: 52565

Looks like you're releasing the view twice.

Your superview is going to keep a reference to your splash image. That will be released when you removeFromSuperview.

If that is the only reference to the splash image then the next line, the release, is going to over-release and cause the crash. Judging by the code you've given, the solution is to remove the explicit release.

However, if there is more code than you've shown it may be a little more complex, though the same idea.

Upvotes: 1

Matthias Bauch
Matthias Bauch

Reputation: 90117

the exception could be caused by the release when you didn't retain the loadingView before.

If you don't retain (with a retain property for example) you are not allowed to release the view.

But to avoid a leak you should double check if it's okay to simply remove the [loadingView release].

Upvotes: 0

Related Questions