我尝试做一个应用程序,但内存分配出现很多崩溃,然后我尝试减少所有代码并清理它,现在我得到了这个
为什么我得到:
在第 101 行分配并存储到“liveello”中的对象的潜在泄漏
- (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;
}