寻找有关如何调试“发送到解除分配的实例的消息”的指针

时间:2011-05-30 04:12:40

标签: objective-c cocoa-touch ios debugging memory-management

我收到以下错误:

  

* - [URLViewController respondsToSelector:]:发送到解除分配的实例0xdb5c3b0的消息

我对如何开始调试很困惑。有人可以给我一些指示,从哪里开始看?

如果你想看,这里有一些代码。这实际上是一个URL拦截器,因此每个链接都会在presentModalViewController

中打开
- (BOOL)openURL:(NSURL *)url{
    URLViewController * web = [[URLViewController alloc] init];
    web.url = url;
    UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:web];
    [nav.navigationBar setTintColor:[UIColor blackColor]];
    [nav setModalPresentationStyle:UIModalPresentationFormSheet];
    [self.detailViewController presentModalViewController:nav animated:NO];
    [web release];
    [nav release];
    return YES;
}

如果对URLViewController实现感兴趣,那么它是:

@implementation URLViewController
@synthesize webview;
@synthesize url;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (IBAction) done:(id) sender
{
    [self dismissModalViewControllerAnimated:YES];   
}

- (IBAction) openInSafari:(id) sender
{
   [(CVore*)[CVore sharedApplication] openURL:url withOverride:NO];
}

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.webview.delegate = self;
     NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [webview loadRequest:requestObj];
    [self.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(done:)]]; 
     [self.navigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(openInSafari:)]]; 
    // Do any additional setup after loading the view from its nib.
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    NSString* title = [webView stringByEvaluatingJavaScriptFromString: @"document.title"];
    self.title = title;
    //self.navigationItem.title = title;
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return YES;
}

@end

更新 跟踪这个之后,我认为我的错误是我需要在[super dealloc]这个之前将UIWebView委托设置为nil吗?当我这样做时,它不再崩溃

1 个答案:

答案 0 :(得分:0)

您已经快速发布了URLViewController个实例,或者您没有保留它。还要检查您使用=的位置,而不是使用合成的setter(可能会创建一个僵尸),如果有的话。没有任何代码可以很难找到帮助。

__

URLViewController已被释放并取消分配时,webview确实应该在您致电super时也是如此,因为它是一个班级成员。但是,对象不能保留其委托(以防止“保留周期”),所以如果你是一些如何在你的webview,这里或其他地方额外保留,它的委托仍然可以最终为零并给出由此产生的崩溃。例如,您有retain的{​​{1}}合成器吗?你有没有随时打过电话?