引用计数的减少不正确

时间:2011-06-05 12:42:48

标签: xcode ios debugging memory-leaks

我收到了filemanager对象的引用计数的不正确的减少。

-(void) checkDb{
BOOL success;
// Create a FileManager object, we will use this to check the status of the database and to copy it over if required
NSFileManager *fileManager = [NSFileManager defaultManager];

// Check if the database has already been created in the users filesystem
success = [fileManager fileExistsAtPath:dbPath];

if (success)
{
    //we found the file, we need to check version
    sqlite3 *db;
    //NSLog(@"Current Databasepath: %@",dbPath);
    // Open the current db (found in the user's filessytem)
    if(sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK) {
        const char *sql = "select dbversion from settings";
        sqlite3_stmt *rs;
        if(sqlite3_prepare_v2(db,  sql, -1, &rs, NULL) == SQLITE_OK) {
            if (sqlite3_step(rs) == SQLITE_ROW) {
                //not eof
                int curDbVersion=sqlite3_column_int(rs,0);
                if (curDbVersion>=minDbVersion){
                    //good dbversion, no need to copy from resources
                    return;
                }
            }
        }
        sqlite3_finalize(rs);
    }
    sqlite3_close(db);
}

//we reached this section which means:
//either database was not found, or invalid db version
//so, we need to copy it from the resources directory (or maybe download it from internet?)

// Get the path to the database in the application package
NSString *dbPathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:dbName];

// Copy the database from the package to the users filesystem
[fileManager copyItemAtPath:dbPathFromApp toPath:dbPath error:nil];

[fileManager release];

}

程序运行正常,但是当我分析它时,我会收到警告。

以下是我收到警告的屏幕截图:

Original: grab.by/ahSi

我可能错过的任何暗示?

2 个答案:

答案 0 :(得分:4)

请注意您正在创建fileManager指针的行:

NSFileManager *fileManager = [NSFileManager defaultManager];

单词copynewallocretain无处可寻:您不拥有fileManager,因此您不应该发布它。

你的最后一行:

[fileManager release];

实际上是在试图释放你当然不拥有的defaultFileManager

答案 1 :(得分:1)

不要release文件管理器 - 它是一个局部变量,稍后会自动释放。