关于访问sqlite的内存泄露问题,请教高手
我写了个访问数据库的程序,将查询的每条结果封装在Dictionary中,在把这多条纪录封装在Array中,代码如下:这是这个方法的片段:
RetuArray=[[NSMutableArray alloc] initWithCapacity:30];
iResult=sqlite3_prepare_v2(database, [Sql UTF8String], -1, &stmt, nil);
if (iResult == SQLITE_OK)
{
while (sqlite3_step(stmt) == SQLITE_ROW)
{
tmpDict=[[NSMutableDictionary alloc] initWithCapacity:10];
for (i=0; i<[Dict count]; i++)
{
//判定拿出的该行数据是什么类型
NSNumber* number;
NSString* pData;
iType=sqlite3_column_type(stmt, i);
switch (iType) {
case SQLITE_INTEGER:
number=[[NSNumber alloc] initWithInt:sqlite3_column_int(stmt,i)];
[tmpDict setObject:number forKey:[Dict objectAtIndex:i]];
[number release];
break;
case SQLITE_TEXT:
pData=[[NSString alloc] initWithUTF8String:(char*)sqlite3_column_text(stmt, i)];
[tmpDict setObject:pData forKey:[Dict objectAtIndex:i]];
[pData release];
break;
case SQLITE_FLOAT:
number=[[NSNumber alloc] initWithDouble:sqlite3_column_double(stmt,i)];
[tmpDict setObject:number forKey:[Dict objectAtIndex:i]];
[number release];
break;
case SQLITE_NULL:
[tmpDict setObject:[NSNull null] forKey:[Dict objectAtIndex:i]];
break;
default:
break;
}
}
[RetuArray addObject:tmpDict];
[tmpDict release];
}
sqlite3_finalize(stmt);
}
return RetuArray;
使用时:如下 NSArray *array=[数据库类 这个方法];
[arral release];
怎么看怎么没有内存泄露,但是在intrument中检查,
pData=[[NSString alloc]initWithUTF8String:(char*)sqlite3_column_text(stmt, i)];
[tmpDict setObject:pData forKey:[DictobjectAtIndex:i]];
这两句有内存泄露,请问高手这是为什么??????? --------------------编程问答--------------------
tmpDict 使用之后有没有release? --------------------编程问答-------------------- tmpDict这个变量在我贴出的代码中生命周期是这样的
tmpDict=[[NSMutableDictionary alloc] initWithCapacity:10];
pData=[[NSString alloc] initWithUTF8String:(char*)sqlite3_column_text(stmt, i)];
[tmpDict setObject:pData forKey:[Dict objectAtIndex:i]];
[pData release];
[RetuArray addObject:tmpDict];
[tmpDict release];
应该是tmpDict加入到数组以后,就释放了 --------------------编程问答-------------------- 除
补充:移动开发 , iPhone