ios fmdb内存泄漏

嗨我问这个问题,我的朋友,正在努力解决这个FMDB内存问题。 他的项目从一个数据库中读取一个列表,他打开数据库并读取每个单元格的数据(这不是一个好主意,但他做了),在init中,init数据库队列,

databaseQueue = [[FMDatabaseQueue alloc] initWithPath:_dbPath]; 

在cellForRowAtIndexPath中,使用configCell来做事情

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString * addressBookTableViewCellIdentifier = @"AddressBookTableViewCell"; AddressBookTableViewCell * cell = (AddressBookTableViewCell*)[tableView dequeueReusableCellWithIdentifier:addressBookTableViewCellIdentifier]; if (cell == nil) { // Create a cell to display an ingredient. cell = [[[AddressBookTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:addressBookTableViewCellIdentifier] autorelease]; cell.selectionStyle = UITableViewCellSelectionStyleBlue; } [self configCell:cell atIndexPath:indexPath]; return cell; 

}

 -(void)configCell:(AddressBookTableViewCell *)aCell atIndexPath:(NSIndexPath *)indexPath{ __block NSDictionary *aUserRecord = nil; NSString *_userName = nil; [databaseQueue inDatabase:^(FMDatabase *db) { [db open]; int offset = 0; offset +=indexPath.row; NSString *str = [NSString stringWithFormat:@"SELECT table_ems_user.pid,\ table_ems_user.user_id,\ table_ems_user.user_name,\ table_ems_user.sex,\ table_ems_user.jid,\ table_ems_user.signature,\ table_ems_user.head\ FROM table_ems_user order by name_spell limit %d,1",offset]; FMResultSet *_rs = [db executeQuery:str]; while ([_rs next]) { aUserRecord = [_rs resultDictionary]; } [_rs close]; [db close]; }]; aCell.textLabel.text = [aUserRecord objectForKey:@"user_name"]; } 

正如你所看到的,从数据库读取并设置到单元格的标签; 用仪器,当滚动tableview时,内存分配会急剧增加(从800k增加到1.6m很快),但是如果你注释行aCell.textLabel.text = [aUserRecord objectForKey:@“user_name”]; 似乎没有太多的内存泄漏比以前的情况下(从800k到约900k)。

通过评论这一行,我们仍然在做db工作,这里很奇怪,一定是有些东西把单元格和db或者块连起来,这就使整个事情变糟。

我检查rs的保留计数,aUserRecord他们是1,似乎正常。 任何块,DB和FMDB专家请分享您的意见,欢呼声

编辑:fdb的inDatabase函数pipe理块进入一个调度队列来处理,我试图删除块,只需使用数据库做的工作,内存问题依然存在,请帮助

也许这可能有帮助。 只是猜测。

 aCell.textLabel.text = [NSString stringWithFormat:@"%@", [aUserRecord objectForKey:@"user_name"]];