2012-06-18 86 views
0

我嘗試做一個應用程序,但我得到了很多崩潰的內存分配,然後我儘量減少所有的代碼,並進行清潔,現在我得到這個電子分配太多的內存

爲什麼我得到:

物體的潛在的泄漏上線101分配並存儲到「livello」

- (id) leggiLivelloDaTabella:(NSString *)tabella { 

NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDir = [documentPaths objectAtIndex:0]; 
NSString *databasePath = [documentsDir stringByAppendingPathComponent:@"DataBase.sqlite"]; 

sqlite3 *database; 

Livello *livello = nil; 

if (sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) { 
    // query che ricava i valori 
    const char *sql = [[NSString stringWithFormat:@"select * from Livelli WHERE Tabella = '%@'",tabella] UTF8String]; 

    sqlite3_stmt *selectstmt; 

    if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) { 
     while(sqlite3_step(selectstmt) == SQLITE_ROW) { 
      // ricaviamo i valori letti dalla query 
      NSString *nomeTabella = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 0)]; 
      NSString *risposteGiuste = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 1)]; 
      NSString *stato = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 2)]; 
      NSString *risposteMinime = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 3)]; 
      NSString *tentativiSbagliati = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 4)]; 
      NSString *tentativiTotali = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 5)];  
      NSString *popUp = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 6)]; 
      NSString *idLivello = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 7)]; 

      livello = [[Livello alloc] initLivelloWithTabella:nomeTabella 
                  rispGiuste:risposteGiuste 
                  statoLivello:stato 
                  rispMinime:risposteMinime 
                tentativiSbagliati:tentativiSbagliati 
                  tentativiTot:tentativiTotali 
                  disaplyPopUp:popUp 
                   idLevel:idLivello]; 
     } 
    } 
    sqlite3_finalize(selectstmt); 
    sqlite3_close(database); 
    selectstmt = nil; 
} 
else 
    sqlite3_close(database); 

return livello; 

}

+1

那麼你是 「黃金」 荷蘭國際集團呢,你在哪裏將其釋放?你有沒有打過[livello發佈]? – trumpetlicks

回答

2

如果不使用ARC(自動引用計數),則應該被標記爲livello AUT orelease。嘗試使用此爲您的return語句:

return [livello autorelease]; 

下面是ARC一些更多的信息:

http://maniacdev.com/ios-5-sdk-tutorial-and-guide/arc-automatic-reference-counting/

http://longweekendmobile.com/2011/09/07/objc-automatic-reference-counting-in-xcode-explained/

+0

謝謝,我不知道我可以返回一個對象並將其釋放...但是我將我的項目恢復爲弧形,現在一切正常! – kikko088