我如何從下面的代碼片段釋放dataArray中,內存泄漏問題?
+(NSMutableArray *)getData: (NSString *)dbPath
{
NSMutableArray *_dataArray = [[NSMutableArray alloc] init];
if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK)
{
NSString *sqlQuery = [NSString stringWithFormat:@"SELECT DISTINCT name FROM databaseTable"];
sqlite3_stmt *selectstmt;
if(sqlite3_prepare_v2(database, [sqlQuery UTF8String], -1, &selectstmt, NULL) == SQLITE_OK)
{
while (sqlite3_step(selectstmt) == SQLITE_ROW)
{
[_dataArray addObject:[NSString stringWithFormat:@"%d", sqlite3_column_int(selectstmt, 0)]];
}
}
sqlite3_finalize(selectstmt);
}
sqlite3_close(database);
return _dataArray;
}
上述方法給我的內存泄漏,它讓我在應用程序的未來工作嚴重問題。
+1遵循推薦的命名約定。 – cbranch 2010-12-07 13:29:04