分析我們的項目Xcode時,在定製的UIBarButtonItem中帶有posibe泄漏通知。 我修正了漏洞,但第二次加載視圖時,[super dealloc]給出了一個EXC_BAD_ACCESS錯誤。super dealloc EXC_BAD_ACCESS錯誤
刪除從的UIBarButtonItem自動釋放(所以返回警告):
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:toolbar] autorelease];
沒有給出問題,同時重新加載屏幕。
定製的UIBarButtonItem和dealloc的代碼:
- (void)viewDidLoad
{
[super viewDidLoad];
// create a toolbar to have the buttons at the right side of the navigationBar
UIToolbar* toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 150, 44.01)];
toolbar.tintColor = [UIColor clearColor];
[toolbar setTranslucent:YES];
// create the array to hold the buttons, which then gets added to the toolbar
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:4];
// Create a comments button
propertiesButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(properties)];
[buttons addObject:propertiesButton];
[propertiesButton release];
// Create a comments button
commentaryButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(comments)];
[buttons addObject:commentaryButton];
[commentaryButton release];
// create a versions button
versionsButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(versions)];
[buttons addObject:versionsButton];
[versionsButton release];
// create a save button
downloadButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemOrganize target:nil action:@selector(download)];
[buttons addObject:downloadButton];
[downloadButton release];
// stick the buttons in the toolbar
[toolbar setItems:buttons animated:NO];
[buttons release];
// and put the toolbar in the nav bar
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:toolbar] autorelease];
[toolbar release];
}
- (void)dealloc
{
[popOverController release];
[propertiesButton release];
[downloadButton release];
[versionsButton release];
[commentaryButton release];
[webView release];
[super dealloc];
}
隨着NSZombieEnabled,我得到
'2011-08-01 10:30:36.571 ProjectName[100:707] *** -[UIBarButtonItem release]: message sent to deallocated instance 0x1fb330'
我們不知道如何解決這個問題。
預先感謝您。
非常感謝!這是一個例程,當我創建一個屬性時,我將它們添加到dealloc方法中。但是當我通過另一個物體時,我也會釋放它們。仍然奇怪的是,xcode告訴我問題出在[super dealloc]上。再次感謝1 – Justin
歡迎! Juzzz! – EmptyStack