我正在使用以下代码片段向Sqlite3数据库添加新元素/行,一切正常,但每次调用此函数时都会产生内存泄漏,有谁能帮我解决这个问题吗?
{
sqlite3 *database;
sqlite3_stmt *addStmt;
NSString *localdescription=@"Enter your Notes here";
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
{
const char *sql = "insert into database(name) Values(?)";
if(sqlite3_prepare_v2(database, sql, -1, &addStmt, NULL) == SQLITE_OK)
{
sqlite3_bind_text(addStmt, 1, [localName UTF8String], -1, SQLITE_TRANSIENT);
if(SQLITE_DONE != sqlite3_step(addStmt))
NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database));
else
//SQLite provides a method to get the last primary key inserted by using sqlite3_last_insert_rowid
NSLog(@"id=====%d",sqlite3_last_insert_rowid(database));
//Reset the add statement.
sqlite3_reset(addStmt);
}
}
sqlite3_close(database);
}