Memory leak problem about access to SQLite, consult a master

I wrote a database program, each query result in the Dictionary packaging, the plurality of record in the Array packaging, the code as follows:

This is the method of fragments:

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++)
{
//To determine whether the data out of what type of
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;

Use: this method follows the NSArray *array=[databaseļ¼½;
[arral release];

How to see how no memory leaks, but check in intrument,
pData=[[NSString alloc]initWithUTF8String:(char*)sqlite3_column_text(stmt, i)];
[tmpDict setObject:pData forKey:[DictobjectAtIndex:i]];
The two have a memory leak, which is why does the master? ? ? ? ? ? ?

Started by Steward at December 17, 2016 - 10:01 PM

TmpDict after use there is no release?

Posted by Caesar at December 21, 2016 - 10:04 PM

The tmpDict variable in the post code is such life cycle

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 should be added to the array, they released

Posted by Steward at January 01, 2017 - 10:20 PM

The response to 2013-11-14 09:07:11 was removed by the administrator

Posted by Sharon at January 11, 2017 - 10:45 PM