gpt4 book ai didi

iphone - super dealloc EXC_BAD_ACCESS 错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:51:46 27 4
gpt4 key购买 nike

在分析我们的项目时,Xcode 在自定义 UIBarButtonItem 中附带了一个 posibe 泄漏通知。我修复了泄漏,但是在第二次加载 View 时,[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'

我们不确定如何解决这个问题。

提前谢谢你。

最佳答案

您将两次释放 propertiesButton、downloadButton、versionsButton、commentaryButton。第一次在 viewDidLoad 中,再次在 dealloc 中。

您不必在 dealloc 中释放它们,因为您已经在 viewDidLoad 中释放了它们。

关于iphone - super dealloc EXC_BAD_ACCESS 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6909918/

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