我使用UINavigationcontroller作为根视图控制器。我不熟悉ARC下的iphone ARC和sqlite操作。
我正在使用Instruments进行测试,因为我收到了内存警告。使用我的应用程序约5-10分钟后,当我注销(为此我使用popToRootViewController)并再次登录Live Bytes继续增加,当我检查调用树 -
[NSObject(NSTreadPerformAdditions) performselectorOnMainThread:withObject:waituntilDone:]
显示 15.91MB字节,并显示
我也在做SQLite操作,在执行这些操作时,它会增加
if(sqlite3_open([[self filePath] UTF8String],& dBObject)!= SQLITE_OK)
为opendatabase,selectquery和update
显示 10MB Live Bytes我第一次使用Instruments测试了我的应用程序,它显示了以下内容:
我现在如何释放这个记忆?
修改
我正在使用此代码来检索数据
-(int)CheckCompanyIsAvailableInTradeList:(NSString *)CompanyId UserId:(NSString *)userId
{
int check=0;
if(sqlite3_open([[self filePath] UTF8String], &dBObject) == SQLITE_OK) {
NSString *sqlStatement =NULL;
sqlStatement = [ NSString stringWithFormat:@"SELECT COUNT(*) FROM tradelist WHERE compnyID = '%@' and UserMasterID ='%@' ;",CompanyId,userId];
if(sqlite3_prepare_v2(dBObject, [sqlStatement UTF8String], -1, &statement, NULL) == SQLITE_OK) {
@autoreleasepool {
while(sqlite3_step(statement) == SQLITE_ROW) {
check = sqlite3_column_int(statement, 0);
}
}
}
sqlite3_finalize(statement);
}
sqlite3_close(dBObject);
return check;
}
无论何时调用此方法,实时字节都会增加 汽车无
答案 0 :(得分:2)
试试这个,
在开始循环之前,你必须打开数据库......
完成后你必须关闭你的数据库..
e.g。
-(void)downloadData
{
[self openDB];// database is open..
// start your loop
for (int i=0; i<[array count]; i++)
{
[self executeInsertQuery];
}
[self closeDb];
}
-(void)openDB
{
if(sqlite3_open([[self filePath]UTF8String],&dBObject)!= SQLITE_OK)
{
sqlite3_close(dBObject);
}
}
-(void)closeDb
{
if (dBObject)
{
int rc = sqlite3_close(dBObject);
NSLog(@"close rc=%d", rc);
if (rc == SQLITE_BUSY)
{
sqlite3_stmt *stmt;
while ((stmt = sqlite3_next_stmt(dBObject, 0x00)) != 0)
{
NSLog(@"finalizing stmt");
sqlite3_finalize(stmt);
}
rc = sqlite3_close(dBObject);
}
if (rc != SQLITE_OK)
{
NSLog(@"close not OK. rc=%d", rc);
}
dBObject = NULL;
}
}
-(Bool)executeInsertQuery
{
NSString* strQuery=[NSString stringWithFormat: @"Insert into list(compnyID,UserMasterID) values('%@','%@');",companyId ,userId ];
char *err;
if (sqlite3_exec(dBObject, [queryString UTF8String], NULL,NULL, &err)!= SQLITE_OK)
{
sqlite3_close(dBObject);
return NO;
}
else
{
return YES;
}
}