2011-06-05 85 views
-1

我收到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

的东西可能我错过任何提示?

回答

4

记下您建立文件管理器的指针行:

NSFileManager *fileManager = [NSFileManager defaultManager]; 

的话copynewalloc,或retain都无处可寻:你没有自己的文件管理器,因此,你应该不释放它。

你的最后一行:

[fileManager release]; 

有效地试图释放defaultFileManager,你当然没有自己。

+0

非常感谢,现在我明白了..我自2周以来一直进入ios开发..并挖掘它..干杯.. – deebee 2011-06-05 13:49:38

1

不要release文件管理器 - 它是一个局部变量,将在稍后自动发布。

+0

+1表示“不要释放文件管理器”,但其原因与变量的范围没有任何关系。只是代码没有分配,复制或保留文件管理器,因此没有业务发布它。 – Caleb 2011-06-05 12:56:52

+0

@Caleb:你说得对。 – 2011-06-05 13:25:59