我將self.notes數組添加到UIPickerView。這是我如何設置陣列:使用sqlite在UIPickerView內存泄漏
NSMutableArray *notesArray = [[NSMutableArray alloc] init];
[notesArray addObject:@"-"];
[notesArray addObjectsFromArray:[dbManager getTableValues:@"Notes"]];
self.notes = notesArray;
[notesArray release];
的UIPickerView的信息從數據庫中採取了這種方法:
-(NSMutableArray *)getTableValues:(NSString *)table
{
NSMutableArray *valuesArray = [[NSMutableArray alloc] init];
if (sqlite3_open([self.databasePath UTF8String], &database) != SQLITE_OK)
{
sqlite3_close(database);
NSAssert(0, @"Failed to open database");
}
else
{
NSString *query = [[NSString alloc] initWithFormat:@"SELECT value FROM %@", table];
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(database, [query UTF8String], -1, &statement, nil) == SQLITE_OK)
{
while (sqlite3_step(statement) == SQLITE_ROW) {
NSString *value =[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)];
[valuesArray addObject:value];
[value release];
}
sqlite3_reset(statement);
}
[query release];
sqlite3_finalize(statement);
sqlite3_close(database);
}
return valuesArray;
}
但我不斷收到在儀器的內存泄漏這些線路:
NSMutableArray * valuesArray = [[NSMutableArray alloc] init];
and
[valuesArray addObject:value];
我在這裏做錯了什麼?
感謝您的幫助!
值不應該在這裏釋放,因爲它不alloced。當容器值ArrayArray泄漏時它正在泄漏。 – taskinoor
謝謝!我所有的泄漏都消失了 – Danamo