【问题标题】:sqlite3_exec is there a memory leak?sqlite3_exec 是否存在内存泄漏?
【发布时间】:2011-05-08 14:28:34
【问题描述】:

我正在使用 SQLite 来存储我的数据。我正在编写包装类,我想知道:如果 (res != SQLITE_OK) 和 errorMsg 将显示在屏幕上会是内存泄漏吗??

所以我需要做 free(errorMsg);在“如果”语句中?谢谢!

-(int) executeQuery: (NSString *) sqlQueryStr
{
char *errorMsg = NULL;
int res = SQLITE_ERROR;

res = sqlite3_exec(database, [sqlQueryStr UTF8String], NULL, NULL, &errorMsg);

if (res != SQLITE_OK)
{
    sqlite3_close(database); 
    NSLog(@"executeQuery Error:  %@", errorMsg);
    database = NULL;
    return res;
}

return res;
}

【问题讨论】:

    标签: iphone memory-leaks sqlite


    【解决方案1】:

    您应该使用sqlite3_free() 释放错误消息字符串,如the documentation

    为避免内存泄漏,应用程序 错误时应该调用 sqlite3_free() 通过返回的消息字符串 sqlite3_exec() 的第 5 个参数 在错误消息字符串为 no 之后 需要更长的时间。

    【讨论】:

      猜你喜欢
      • 2011-01-29
      • 2011-06-26
      • 2011-10-07
      • 1970-01-01
      • 1970-01-01
      • 2012-09-13
      • 2020-07-22
      • 2010-10-13
      • 2019-01-28
      相关资源
      最近更新 更多