2011-05-30 20 views
1

我收到以下錯誤「發送到釋放實例消息」指針:尋找關於如何調試

* -[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 

UPDATE: 跟蹤此之後,我認爲我的錯誤在這裏是我需要將UIWebView委託設置爲零,然後[超級dealloc]這是正確的?當我這樣做時,它不再崩潰

+1

@adit:如果我們有一些代碼可以幫助我們,那麼這將對我們有所幫助。 – SK9 2011-05-30 04:19:22

+1

打開'NSZombies' – zneak 2011-05-30 04:29:47

+0

沒有人想爲down vote.so刪除帖子是更好的選擇 – Ishu 2011-05-30 05:18:44

回答

0

您已經發布了URLViewController實例,或者您沒有保留它。同時檢查你使用=的位置,而不是使用合成的setter(可能會創建一個殭屍),如果有的話。如果沒有任何代碼,很難獲得幫助。

__

URLViewController已被釋放,釋放,你真的webview應該太的時候,你打電話super因爲它是一個類成員。然而,對象不能保留他們的代表(爲了防止「保留循環」),所以如果你是一些如何在你的web視圖上留下額外的保留,這裏或其他地方,它的代表仍然可以最終爲零,併產生崩潰。例如,你有retain合成器爲webview?你有沒有在任何時候打過電話?

+0

添加了一些代碼...不知道它是否有幫助 – adit 2011-05-30 05:26:25

+0

不,我沒有添加任何額外的保留..我認爲這個問題更多的是發送消息後,它已被釋放一個代表... webview是從IB我只是把它連接起來 – adit 2011-05-30 14:45:50