hi Im asking this question for my friend, who is struggling with this fmdb memory issue. his project read a list from a db, and he opens the db and read the data for each cell, (which is not a good idea but he did), in init, init the database queue,
databaseQueue = [[FMDatabaseQueue alloc] initWithPath:_dbPath];
in cellForRowAtIndexPath, use configCell to do things
- (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"];
}
as you can see, read from DB and set to cell's label; with instrument, when scrolling the tableview, memory allocations increases dramatically(from 800k increases to 1.6m very soon), but if you comment the line aCell.textLabel.text = [aUserRecord objectForKey:@"user_name"]; seems no much memory leaks than the previous scenario,(from 800k to about 900k).
by comment the line, we still do the db work, it's strange here, must be some thing links the cell and db or block, which makes the whole thing bad.
I check the retain count of rs,aUserRecord they are 1, and seems normal. any expert in block, DB, and FMDB pls share your opinions, cheers
EDIT: the fmdb inDatabase function manages the block in to a dispatch queue to process, I tried to remove the block , simply use the db to do the job, memory issues remains, pls help
Maybe this could help. Just guessing.