gpt4 book ai didi

objective-c - 寻找有关如何调试 "message sent to deallocated instance"的指针

转载 作者:行者123 更新时间:2023-11-28 17:45:37 26 4
gpt4 key购买 nike

我收到以下错误:

* -[URLViewController respondsToSelector:]: message sent to deallocated instance 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 委托(delegate)设置为 nil 这是正确的吗?当我这样做时,它不再崩溃

最佳答案

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

__

URLViewController 被释放和释放时,你的 webview 在你调用 super 时真的应该也是,因为它是一个类成员。但是,对象不能保留它们的代表(以防止“保留循环”),所以如果你想知道如何在你的 webview 上添加额外的保留,在这里或其他地方,它的代表仍然可能最终为 nil 并导致崩溃.例如,您是否有用于 webviewretain 合成器?你有没有调用这个?

关于objective-c - 寻找有关如何调试 "message sent to deallocated instance"的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6172214/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com