开发者

When pushViewController: pointer being freed was not allocated

开发者 https://www.devze.com 2023-02-24 23:41 出处:网络
I cannot find the problem! Any help on this will be highly appreciated: From a UITableView I\'m pushing a new view containing a view with a UIwebView to access to internet. When the back button is cli

I cannot find the problem! Any help on this will be highly appreciated: From a UITableView I'm pushing a new view containing a view with a UIwebView to access to internet. When the back button is clicked I'm getting the next error: malloc: * error for object 0x3d438: pointer being freed was not allocated. However when I comment the last line (when the dvController is released) all is working fine!!!

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
    [self setCellIdxPathSelected:indexPath];

    NSString *selectedID = [[theList objectAtIndex:indexPath.row] theWebID]; 

    ExternalWebView *dvController = [[ExternalWebView alloc] initWithNibName:@"ExternalWebView" bundle:nil];开发者_开发问答

    dvController.hidesBottomBarWhenPushed= YES;
    dvController.theWebID= selectedID;

    NSLog(@"El ID: %@", selectedID);

    [self.navigationController pushViewController:dvController animated:YES];

    [dvController release]; // ERROR !!!
}


Try creating dvController with autorelease:

ExternalWebView *dvController = [[[ExternalWebView alloc] 
       initWithNibName:@"ExternalWebView" bundle:nil] autorelease];

and then remove the [dvController release] statement.

The confirmation that you are not leaking will come if you run Instruments with the Leaks tool and verify that you are not, in fact, leaking dvController.

My hunch is that your controller is getting released by another object that your object has somehow become a subview of. I have seen this behavior before in another situation.

Of course, if the above changes also cause a crash, then there is a deeper issue and I think we'll need a little more info about ExternalWebView.

0

精彩评论

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