开发者

memory bad access?

开发者 https://www.devze.com 2023-03-10 20:12 出处:网络
How can this statement ever give me bad access? myWebView = [[NewsWebViewController alloc] initWithNibName:开发者_C百科@\"NewsWebViewController\" bundle:nil];

How can this statement ever give me bad access?

myWebView = [[NewsWebViewController alloc] initWithNibName:开发者_C百科@"NewsWebViewController" bundle:nil];
[[self.view.superview superview] addSubview:myWebView.view];

 if(myWebView!=nil) {
    [myWebView release];
    myWebView = nil;
}

Ive ran it through instruments and it crashes every time. myWebView is an ivar in my header file.

Any thoughts? Many thanks

Jules


ok here is the actual issue. When I removed the webview it gets dealloc'd but I didnt set its delegate to nil. Therefore webViewDidFinishLoading etc was trying to access it and giving me bad access.

Thanks to all for your input.


You should check that myWebView is nil before you add it's view to a subview. You do not need to set myWebView to nil after you release it.


You are setting mywebview to nil after releasing so it crashes as the object no longer exists. Do it in this order:

if(myWebView!=nil) {

  myWebView = nil;
  [myWebView release];

}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号