释放thread1 exc_bad_access
Posted
技术标签:
【中文标题】释放thread1 exc_bad_access【英文标题】:releasing thread1 exc_bad_access 【发布时间】:2012-08-24 07:04:32 【问题描述】:我是 ios 编程新手,我的程序运行良好,但我发现它有内存泄漏,所以我开始释放对象。
当我现在启动程序时,它给了我一个错误:
@autoreleasepool
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
和:
Thread 1: EXC_BAD_ACCESS (code = 1, address = 0x3f800010)
我尝试调试它,我发现程序在创建 tableView 时崩溃了。 它创建了整个第一部分,但在第二部分的第二行中,它在返回行中崩溃了。
这是我创建表的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
[tableView setBackgroundView:nil];
tableView.backgroundColor = [UIColor clearColor];
// Configure the cell...
if ([self tableView:tableView canCollapseSection:indexPath.section])
if (!indexPath.row)
static NSString *CellIdentifier = @"TitleCell";
UILabel *title;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = nil;
if (cell == nil)
[[NSBundle mainBundle] loadNibNamed:@"TitleCell" owner:self options:nil];
titleCell.layer.masksToBounds = YES;
titleCell.layer.cornerRadius =0.0;
cell = titleCell;
self.titleCell = nil;
title =(UILabel *)[cell viewWithTag:1];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
NSString *orderString=[[[NSString alloc] init] autorelease];
title.text = [[titles objectAtIndex:indexPath.section] objectAtIndex:2];
cell.accessoryView = nil;
if (!isPad())
[cell.contentView setBackgroundColor:[UIColor colorWithRed:0.0 green:0.18 blue:0.24 alpha:1]];
return cell;
else
// all other rows
static NSString *CellIdentifier = @"DataCell";
UILabel *title;
UILabel *update;
UILabel *download;
UILabel *updateText;
UILabel *downloadText;
UIImageView *favoriteIcon;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = nil;
if (cell == nil)
[[NSBundle mainBundle] loadNibNamed:@"DataCell" owner:self options:nil];
cell = dataCell;
self.dataCell = nil;
cell.layer.cornerRadius =0;
title =(UILabel *)[cell viewWithTag:1];
download = (UILabel *)[cell viewWithTag:3];
update = (UILabel *)[cell viewWithTag:2];
favoriteIcon = (UIImageView *)[cell viewWithTag:4];
updateText = (UILabel *)[cell viewWithTag:5];
downloadText = (UILabel *)[cell viewWithTag:6];
updateText.text = NSLocalizedString(@"updated", nil);
downloadText.text = NSLocalizedString(@"downloaded", nil);
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MM. d. YYYY"];
starIcone = favoriteIcon;
int indicator = 0;
for (int i=0; i<[allData count]; i++)
if ([[[allData objectAtIndex:i] objectAtIndex:1] isEqualToNumber:[[titles objectAtIndex:indexPath.section] objectAtIndex:0]] )
indicator++;
if (indicator == indexPath.row)
title.text = [[allData objectAtIndex:i] objectAtIndex:2];
download.text = [dateFormat stringFromDate:[self db_get_date:[[[allData objectAtIndex:i] objectAtIndex:0]intValue]]];
update.text = [dateFormat stringFromDate:[[allData objectAtIndex:i] objectAtIndex:3]];
break;
[dateFormat release];
[favoriteIcon setAccessibilityHint:title.text];
if ([favorits count]==0)
favoriteIcon.image = [[UIImage alloc]
initWithContentsOfFile:
[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:
@"blankstar.png"]];
for (int i=0; i<[favorits count]; i++)
if ([title.text isEqualToString:[[favorits objectAtIndex:i] objectAtIndex:2]])
favoriteIcon.image = [[UIImage alloc]
initWithContentsOfFile:
[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:
@"star.png"]];
break;
else
favoriteIcon.image = [[UIImage alloc]
initWithContentsOfFile:
[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:
@"blankstar.png"]];
UITapGestureRecognizer *recognizer = [[[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(AddIcone:)]autorelease
];
[favoriteIcon setUserInteractionEnabled:YES];
[favoriteIcon addGestureRecognizer:recognizer];
cell.backgroundColor = [UIColor clearColor];
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
return cell;
return nil;
我也试过把:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
static NSString *CellIdentifier = @"TitleCell";
UILabel *title;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = nil;
if (cell == nil)
self.titleCell = [[[NSBundle mainBundle] loadNibNamed:@"TitleCell" owner:self options:nil]objectAtIndex:0];
titleCell.layer.masksToBounds = YES;
titleCell.layer.cornerRadius =0.0;
cell = titleCell;
self.titleCell = nil;
return cell;
它像以前一样崩溃。
请帮助我并感谢您的帮助。
【问题讨论】:
【参考方案1】:[[NSBundle mainBundle] loadNibName: owner: options:]
返回一个数组。
将此行替换为:
self.titleCell = [[[NSBundle mainBundle] loadNibNamed:@"TitleCell" owner:self options:nil] objectAtIndex:0];
【讨论】:
您好,非常感谢您的快速回复,但没有成功。它仍然在同一行崩溃。 如果它在你的 main 方法中崩溃而不是启用异常刹车点。这可以向您显示崩溃的确切路线。此外启用僵尸。这将告诉您哪个实例和方法导致错误访问。以上是关于释放thread1 exc_bad_access的主要内容,如果未能解决你的问题,请参考以下文章
UIButton 在 Swift 中抛出 Thread1: EXC_BAD_ACCESS (code=1, address 0x...)
EZAudio 不起作用:创建 EZRecorder 实例时的 Thread1 EXC_BAD_ACCESS
线程 1:EXC_BAD_ACCESS(代码=1,地址=0x200)