0

下面的代碼是在的tableView didSelectRowAtIndexPath方法如果釋放是註釋掉我得到的錯誤:釋放給我EXC_BAD_ACCESS錯誤

ComicDetailsViewController * comicDetailsViewController = [[ComicDetailsViewController alloc] initWithNibName:@"ComicDetailsViewController" bundle:nil]; 
     comicDetailsViewController.comic = (Comic *)[arrayOfComics objectAtIndex:indexPath.row]; 
     comicDetailsViewController.bLoadPerformances = YES; 
     [self.navigationController pushViewController:comicDetailsViewController animated:YES]; 
     //[comicDetailsViewController release]; 

的錯誤不會立即發生,它發生一次我點擊omicDetailsViewController中的後退按鈕。

ie。)我選擇tableview行,下一個視圖加載並正常工作。一旦我完成了該視圖,並單擊後退導航按鈕程序崩潰,並給我exc_bad_access。爲什麼是這樣?

編輯:

#0 0x9682b176 in __kill 
#1 0x9682b168 in kill$UNIX2003 
#2 0x968bd89d in raise 
#3 0x968d39bc in abort 
#4 0x968c2164 in szone_error 
#5 0x968c21e7 in free_small_botch 
#6 0x000a7877 in -[NSConcreteMutableData dealloc] 
#7 0x00006433 in -[ComicDetailsViewController dealloc] at ComicDetailsViewController.m:376 
#8 0x003cbcc7 in -[UINavigationController setDisappearingViewController:] 
#9 0x003c9219 in -[UINavigationController _clearLastOperation] 
#10 0x003c9b62 in -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] 
#11 0x0055224a in -[UINavigationTransitionView _notifyDelegateTransitionDidStopWithContext:] 
#12 0x0055338a in -[UINavigationTransitionView _navigationTransitionDidStop] 
#13 0x0034829d in -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] 
#14 0x0034812f in -[UIViewAnimationState animationDidStop:finished:] 
#15 0x0244ca28 in run_animation_callbacks 
#16 0x0244c8e9 in CA::timer_callback 
#17 0x02688d43 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ 
#18 0x0268a384 in __CFRunLoopDoTimer 
#19 0x025e6d09 in __CFRunLoopRun 
#20 0x025e6280 in CFRunLoopRunSpecific 
#21 0x025e61a1 in CFRunLoopRunInMode 
#22 0x02f0c2c8 in GSEventRunModal 
#23 0x02f0c38d in GSEventRun 
#24 0x00326b58 in UIApplicationMain 
#25 0x000020f4 in main at main.m:14 

編輯2:

這裏是comicDetailsViewController的dealloc塊:

- (void)dealloc { 
[comic release]; 
[xmlParser release]; 
[webData release]; 
[currentPerformanceObject release]; 
[arrayOfPerformances release]; 
[soapResults release]; 
[btnPerformances release]; 
[super dealloc]; 

}

376行是WEBDATA釋放線

編輯3:

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error 
{ 
    NSLog(@"ERROR with theConenction"); 
    [connection release]; 
    [webData release]; 
} 

-(void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
    NSLog(@"DONE. Received Bytes: %d", [webData length]); 

    if(xmlParser) 
    { 
     [xmlParser release]; 
    } 

    xmlParser = [[NSXMLParser alloc] initWithData: webData]; 
    [xmlParser setDelegate: self]; 
    [xmlParser setShouldResolveExternalEntities: YES]; 
    [xmlParser parse]; 

    [connection release]; 
    [webData release]; 
} 
+0

顯示堆棧跟蹤。 – 2010-11-26 04:52:45

+0

嗯,文字很有趣。這是你的意思棧追蹤? – Mausimo 2010-11-26 05:04:49

+0

請在你的`ComicDetailsViewController`類 – 2010-11-26 05:08:36

回答

1

請向我們展示堆棧跟蹤。

但我最初的猜測是你在ComicDetailsViewController類的- (void) dealloc中做錯了。

請檢查幾件事情

  • dealloc塊是好的
  • 您還沒有釋放comicDetailsViewController對象或從別的地方對它的引用。

希望這會有所幫助。

感謝, Madhup

0

之前彈出視圖中移出,通過發送取消消息給合適的對象取消NSURLConnection的。

假設你NSURLConnection的對象名爲asyncConnection:

-(void)viewWillDisappear:(BOOL)animated 
    [asyncConnection cancel]; 
} 
0

問題仍可能處於您的dealloc。

僅僅因爲該對象位於@interface(.h文件)中,這並不意味着您可以/不得不釋放該變量。我有這個問題,以及

.h文件中

@interface PeopleViewController : UITableViewController { 
NSArray *people; 
} 

@property (nonatomic, retain) NSArray *people; 

@end 

。M檔

@implementation PeopleViewController 

@synthesize people; 

- (void)viewDidLoad { 
    people = [town.people allObjects]; 
} 

... 

- (void)dealloc { 
    [people release]; 
} 

@end 

我並不需要釋放的人,因爲我並沒有增加對象的保留計數而在我的自定義視圖,因此在dealloc的過程中釋放它引起了我的問題。