gpt4 book ai didi

ios - 查询sqlite数据库时内存分配不断增加

转载 作者:行者123 更新时间:2023-11-28 22:02:39 25 4
gpt4 key购买 nike

+ (BOOL) isExistingTicket:(NSString *)TicketID{
int numrows=0;

sqlite3 *database;

NSString *dbPath = [documentsDirectory stringByAppendingPathComponent:dbName];
if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK)
{
NSString *sqlString = [NSString stringWithFormat:@"select count(*) from tickets WHERE ticket_id = '%@' LIMIT 1",TicketID];
sqlite3_stmt *selectStatement;


int returnValue = sqlite3_prepare_v2(database, [sqlString UTF8String], -1, &selectStatement, NULL);


if (returnValue == SQLITE_OK)
{
if(sqlite3_step(selectStatement) == SQLITE_ROW)
{
numrows= sqlite3_column_int(selectStatement, 0);
}
}


sqlite3_finalize(selectStatement);
}
else
sqlite3_close(database);

if (numrows > 0) {
return YES;
}else{
return NO;
}

大约 200 个比较的数据集正在我的应用程序中使用此查询。多次调用此函数时,应用程序内存使用量不断增加。它消耗超过 25Mb,之后不会减少。为什么会这样?您能提出任何优化建议吗?

最佳答案

此代码仅在 sqlite3_open 调用失败时关闭数据库。

sqlite3_close 调用移动到 if 的第一个分支。

关于ios - 查询sqlite数据库时内存分配不断增加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24756331/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com