iphone – 使用SQLite3 API时Xcode内存泄漏

前端之家收集整理的这篇文章主要介绍了iphone – 使用SQLite3 API时Xcode内存泄漏前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用以下代码片段将新的元素/行添加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],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);
}

解决方法

您应该最终确定不再使用的任何准备好的声明:

sqlite3_finalize(addStmt),addStmt = nil;

没有必要将指针设置为nil我只是真的喜欢它.

猜你在找的Xcode相关文章